Ask Your Question
0

Laplacian output has many white dots (noise)

asked 2018-08-15 20:52:15 -0600

jkjk24 gravatar image

updated 2018-08-16 19:42:09 -0600

Hi,

I applied Gaussian, and then laplacian to images. The output has many white dots. Please check the following 2 outputs.

image description

images[i].convertTo(img, CV_32F, 1.0f / 255.0f);
GaussianBlur(img, img, Size(5,5), 0, 0, BORDER_DEFAULT );
if (channels == 3) {
cvtColor(img, gray, COLOR_RGB2GRAY);
}
else {
img.copyTo(gray);
}
Laplacian(gray, contrast, CV_32F);

Could someone please explain why? And how to solve it? Thank you!

EDIT: The above code is shown to be valid by LBerger's post. My problem is due to the normalization of the 2 output images by their sum. After division, some pixels tend to infinity. Shown by my following code here

for (size_t i = 0; i < images.size(); i++) {    
    contrast_sum = constrast[i]
}
for (size_t i = 0; i < images.size(); i++) {
    contrast[i] /= contrast_sum;
}
edit retag flag offensive close merge delete

Comments

1

You should post your original image if you want other people being able to reproduce your issue.

Eduardo gravatar imageEduardo ( 2018-08-16 19:33:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2018-08-16 02:49:34 -0600

LBerger gravatar image

updated 2018-08-16 02:58:08 -0600

I cannot reproduce your problem using this code :

int main(int argc, char* argv[])
{
Mat img = imread("g:/lib/opencv/samples/data/baboon.jpg", IMREAD_COLOR);
if (img.empty())
{
    cout << "check path";
    exit(-1);
}
img.convertTo(img, CV_32F, 1.0f / 255.0f);
imshow("original", img);

Mat gray,contrast;
GaussianBlur(img, img, Size(5, 5), 0, 0);
imshow("blur", img);
if (img.channels() == 3) {
    cvtColor(img, gray, COLOR_BGR2GRAY);
}
else {
    img.copyTo(gray);
}
Laplacian(gray, contrast, CV_32F);
imshow("Laplacian", 10 * contrast);
normalize(contrast, contrast, 1,0,NORM_MINMAX);
imshow("Laplacian Normalize", contrast);
waitKey(0);
return 0;
}

image description

edit flag offensive delete link more

Comments

2

Hi LBerger, Thank you so much for the help. I realized the problem is with the latter part of the code. I normalized the 2 output images by their sum. For some pixels, their sum is so small that make the result tend to infinity after division. However, you showed me a great way to debug. I'll start displaying the intermediate Mats, and not make silly division mistakes :)

jkjk24 gravatar imagejkjk24 ( 2018-08-16 19:37:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-08-15 20:52:15 -0600

Seen: 965 times

Last updated: Aug 16 '18