Tutorial :Erosion in MATLAB



Question:

When I apply erosion to my image to find a small ball or disk shaped objects, no matter how much I change the size of the structuring element it doesn't seem to work. Instead the entire image appears kind of smudged by the structuring elements. I can still see where the objects are, but it doesn't help me locate them. Is there a way to refine this technique?


Solution:1

InsertNickHere touched on what I think your confusion is, without explicitly explaining it. It sounds like you're expecting the results that erode/dilate/open/close give with a binary image. Performing those operations on a typical grayscale image will give the behavior you're getting.

If you can, try converting your image to a binary image (by thresholding, probably), and then performing your morphological operations on it.


Solution:2

If it's grayscale you might want to look into preprocessing with filters.


Solution:3

You should always use opening/closing. Your erosion will "damage" the objects that you want to find, so you should do dilation after. This is was opening/closing does. Here is a small MATLAB program for detecting "blobs" in an image:

Ib = binary_image // Whatever image  [L, n] = bwlabel(Ib);  RGB = label2rgb(L, 'spring', 'c', 'shuffle');  figure, imshow(RGB);  imwrite(RGB, 'segmented.jpg');  stats  = regionprops(L)  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »