Search code examples
matlabimage-processingwatershed

Watershed - local minima in greyscale image


I have a set of greyscale images where I need to locate the local minima. I'm writing my code in Matlab and I'm looking for suggestions on how to structure the algorithm: do I need to calculate the gradient or can I just use the watershed function?

This is the code I used to do a first analysis (images below):

IM_c = imcomplement(IM);
L = watershed(IM_c);
Lrgb = label2rgb(L);
figure; hold on;
subplot(3,1,1); imshow(IM_c); hold on;
subplot(3,1,2); imshow(Lrgb);hold on;
subplot(3,1,3); imshow(imfuse(IM_c,Lrgb));

enter image description here

Intuitively, I expect to find regional minima in the pixels pointed by arrows:
enter image description here


Solution

  • I guess the solution would be to use a gradient image, following the algorithm described in this paper. The procedure is quite complicated, so instead I

    1. Cleaned the image using imerode and imdilate;
    2. Made a binarized version (IM_bin) of the image and used it as a filter, so that if IM_bin(x,y) > 0
      IM_clean(x,y) = IM(x,y); else IM_clean(x,y) = 0;
    3. Used imerode again;
    4. Looked for regional maxima using imregionalmax.