c++ - OpenCV - Not getting desired output while applying Laplacian filter -


i'm working in opencv c++. have taken classical lena image , applied gaussian noise of mean , variance noised_lena. applied average filter on noised image , obtained averaged image blurred image.

now when apply laplacian filter has correctly detect edges not correct output. i'm not getting desired output expected image should where, 1 can detect edges cleanly . code given below.

thanks in advance.

int main(int argc, char *argv[]) {     int i, dim, k, l, j;     float res=0.0;     mat m = imread(argv[1],0); //input image in m     mat n(m.rows, m.cols, cv_8u);//image obtained after applying average filter     mat lap_n(m.rows, m.cols, cv_8u);//padding n zeros based on filter size given user     mat lap(m.rows,m.cols,cv_8u);// image obtained after applying laplacian filter     cout << "enter size of filter u want odd number only"<<endl;     cin >> dim;     mat pad_m((m.rows+((dim-1))), (m.cols+((dim-1))), cv_8u);     mat lap_m((m.rows+((dim-1))), (m.cols+((dim-1))), cv_8u);     copymakeborder(m, pad_m,dim/2,dim/2,dim/2,dim/2, border_constant, 0);     /*average filter*/     for(i=0;i<=pad_m.rows-dim;i++)     {         for(j=0;j<=pad_m.cols-dim;j++)         {   res = 0.0;             for(k=0;k<dim;k++)             {                    for(l=0;l<dim;l++)                 {                        res += pad_m.at<uchar>(i+k,j+l);                 }              }             res = res/(dim*dim);             n.at<uchar>(i, j)=(uchar)((int)(res));         }     } /* laplacian filter*/        copymakeborder(n, lap_m,dim/2,dim/2,dim/2,dim/2, border_constant, 0);     res = 0;     for(i=0;i<=lap_m.rows-dim;i++)     {         for(j=0;j<=lap_m.cols-dim;j++)         {             res = 0.0;             for(k=0;k<dim;k++)             {                    for(l=0;l<dim;l++)                 {                        if(k==dim/2 && l==dim/2)                     {                         res =res - (((dim*dim)-1)*((float)lap_m.at<uchar>(i+k,j+l)));                     }                     else                     {                         res += lap_m.at<uchar>(i+k,j+l);                     }                 }              }              lap_n.at<uchar>(i, j)=(uchar)((int)(res));         }     }      imshow("original", m);     imshow("padded", pad_m);     imshow("averaged", n);     imshow("laplacian", lap_n);     //imwrite("lap2,500,5*5_lena.png",lap);     waitkey(0);     return 0; } 

i performed image normalization on blurred image provided:

cv2.normalize(gray, alpha=5, beta=0, norm_type=cv2.norm_minmax, dtype=cv2.cv_32f)

after applied laplacian filter able obtain :

enter image description here

note: perform image normalization make sure image of type float


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -