Laplacian output has many white dots (noise)

Hi,

I applied Gaussian, and then laplacian to images. The output has many white dots. Please check the following 2 outputs. 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 close merge delete

1

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

Sort by » oldest newest most voted

I cannot reproduce your problem using this code :

int main(int argc, char* argv[])
{
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;
} more