MATLAB: How to create a good mask of the algae without reading into too much noise

algaedigital image processingimage processingImage Processing Toolboximage segmentation

The goal is to produce a (binary) mask on the algae and I attempted following steps:
– turn image gray with default function rgb2gray()
– image smoothing by gaussian filtering with sigma 0.5
– obtain image gradient with ingredient() using 'CentralDifference'
– Sobel Edge detection
– Canny Edge detection 2 times
– image dilation with square shape structural elements size 2 pixels and fill in
– image erosion with diamond shape size 3 pixels
The result is not good. The main problem is that my program has a hard time figuring out the ambiguous contour of the original image. It also reads into too much noise (I suspect it will get better if I increase the sigma of gaussian filter)
Can someone help me with this? I have some other 500 images that I need to create masks for. They are all of the same color tone (gray green type)

Best Answer

The problem is that the algae virtually disappears at points. So this is actually one situation where an edge filter might actually help. So try some. I see you did and weren't happy with the results. Well those were easy ones to try since they're built in, but perhaps not the best. You might try a DOG filter (Difference of Gaussians). Or try a Frangi or Hessian filter - there are File Exchange entries for those. If you still get a tube with choppy edges, then you'll have to try to make them straighter. In that case either try activecontour() (demo attached), or maybe Hough() or houghlines(). If the algae tubules are always straight lines, then you might be able, and need to, use RANSAC. You could avoid this if you could somehow stain the algae, or use fluorescence photography if fluoresces.
The easy part is to get rid of the small noise blobs once you have the binary image. Just use bwareaopen() or bwareafilt().