Detect irregular dark spots in a gray scale image.

I require ideas to detect these kind of black spots in a gray scale image.
I have tried applying Canny and Sobel edge detectors (with various thresholds) but didn't get good results. There's a lot of noise.
Visually, there's stark difference between the bottle and the black hole. But the log filter output doesn't show this high difference. Moreover, only the small boundary around the hole is detected. (FYI: the drop kind of shape on the left shouldn't be detected since it's not a defect.)
Is there any other method I can use?
I have attached the gray scale image.
This is the output of imadjust(GrayImg). What function can I use to find the encircled regions?
Kindly note that I am able to segment the bottle. So basically, I am ignoring the top and bottom 300 rows, and left and right 100 columns in all images.

Answers (1)

First of all, make a mask that includes only the bottle but not the "okay" region at the left of it. Then run a texture filter over the masked image, like stdfilt(). Then threshold.

4 Comments

Thanks.
Yes, I have made a mask and segmented only the bottle. I tried using stdfilt() but am still not able to identify the defected region. I have attached the mask for your reference.
1. To mask the drop shaped region (on the left), I have to identify that region first. How can I do that? In some cases, the drop will not be present.
2. Kindly note that there may be a similar pin-hole/defected ("not okay") region lying within the drop (left of bottle). So I cannot consider this region as always "okay"
I was wondering if there's a way I can use the gradient in intensity values. Near the drop shaped region, the intensity changes smoothly. This is not so in the two defected regions marked. Over a small region, the range / gradient is high. I have tried rangefilt() as well, but couldn't find satisfying results.
You can use rangefilt() or stdfilt() or entropyfilt() and try to adjust the parameters. Or else try to use adapthisteq() to try to flatten the background and then use global filters and thresholds.
I have tried the Texture Analysis functions ( rangefilt, stdfilt and entropyfilt ) with different NHOOD matrices.
When I used CLAHE ( adapthisteq ), I found that the drop shape also gets highlighted.
Till now, the best method for my case has been LOG filter:
filt_img = imfilter(GrayImg_dbl, fspecial('log',31,5));
This does not detect the small black pinhole though.

Sign in to comment.

Asked:

on 6 Nov 2015

Commented:

on 13 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!