# How to detect discolorations in an image?

I'm evaluating the technical quality of an images and I'd like to scan it for defects from dirty sensors. Are there any filters to quickly detect a blob of discoloration? Here are a few examples:

• Broken pixels and dust on the matrix are always sitting at fixed place. Therefore, you need to record video (or fast frame sequence) of dynamic scene and just look for correlation over long frame sequence. Another thing is pixel noise. It is the same camera-related defect but it is randomly generated at each frame. I guess the Fourier spectrum of such noisy image should contain short-periodic components which amplitude is proportional to amount noise . Aug 26 '16 at 6:59
• If you can generate desired images, then sensor noise or surface defects can be imaged by us of a small aperture (say f/22) and making two images of a reasonably uniform background. A visual flicker compare or correlation of the two images with show a sensor noise. | As suggested by Rom38, you can correlate existing images - with results improved by small aperture and increasing number of images used. Aug 26 '16 at 8:49
• See also this post photo.stackexchange.com/questions/21640/… Aug 26 '16 at 10:53
• If you only have access to individual images taken at unknown times, but not the camera itself, please indicate that. Comments and answers seem to assume that you are able to take any number of images with the same camera with arbitrary settings and compare them. Sep 6 '16 at 8:18
• I'm sure wavelet analysis can do this,so I add that tag,but I don't know how to do it.
– yode
Apr 14 '17 at 20:21

If you can generate desired images, then sensor noise or surface defects can be imaged by use of a small aperture (say f/22) and making two images of a reasonably uniform background.
A visual flicker compare or correlation of the two images with show a sensor noise.
For '35mm' digital images I find a relatively uniform area - a wall or the sky is usually good enough, and set the camera for an exposure of say 1 to 4 seconds. I then defocus the image and "wave" the camera pseudo randomly across the target area during the exposure. This typically gives a near uniform detail free image. (Blue biased for the sky, green for a wall of foliage etc.) Comparison of two images makes sensor noise and similar very visible.

As suggested by Rom38, you can correlate existing images - with results improved by small aperture and increasing number of images used.

• Hmmm. Downvoter at work. Strange. Not 103% correlated with query but "useful" in the context. Sep 10 '16 at 0:27

I'm still working on it and there still can be a lot improvements in my work, but I think it's a good thing to let you know there's still someone working on this interesting question.

detect[img_, th_: .04, filt_Integer: 2, bin_Integer: 5,size_:25] :=
Block[{imgp, disks},
imgp = LocalAdaptiveBinarize[LaplacianGaussianFilter[img, filt],
bin, {1, 0, th}];
disks =
ComponentMeasurements[
imgp, {"Centroid", "EquivalentDiskRadius"}, #Count < size &];
HighlightImage[img, Disk @@@ disks[[;; , 2]]]]


then run detect[img1] where img1 is the second picture with a almost uniform background, we can get a fairly good detection!

but as you can see, in other pictures with not that good uniformity over regions, things could go messy, so I'm trying to use some other filter like EntropyFilter or StandardDeviationFilter to map out the area in which blobs can possibly be found. By saying "possibly be found", I mean even people cannot find blobs in a not that uniform region as we cannot be sure whether it is a blob or a real stuff!

But as your ultimate question is

Are there any filters to quickly detect a blob of discoloration?

Then my answer is LaplacianGaussianFilter, EntropyFilter and StandardDeviationFilter. The first finds out blobs and the latter two tell which of them are valid.

Hope this can help.

• Lightroom has a feature to make it easier to see these dust spots. Google for "lightroom visualize spots". By the looks it works by increasing (local?) contrast and doing edge detection. Since most such spots are circular, they will be easier to spot. But they aren't always circular, see examples. As a human, I rely not only on spotting the shape of a spot, but also knowing what to exact in that region of the image. No well-defined spots are expected in the sky, of any shape. No circles are expected among natural forms. Sep 12 '16 at 12:50