How to take mean for watershed algorithm?

john asked on 7 Feb 2012
Latest activity: Answer by Sven on 7 Feb 2012

I applied watershed algorithm successfully.But I don't know how to take the mean of the result after applying that algorithm.

0 comments

Products

    1 answer

    Sven answered on 7 Feb 2012

    Hi John,

    Step 1: Take your watershed (I'm just copying an example from the MATLAB docs, you will obviously have your own image I, and watershed L variables):

    rgb = imread('pears.png'  );
    I = rgb2gray(rgb);
    hy = fspecial('sobel');
    hx = hy';
    Iy = imfilter(double(I), hy, 'replicate');
    Ix = imfilter(double(I), hx, 'replicate');
    gradmag = sqrt(Ix.^2 + Iy.^2);
    se = strel('disk', 20);
    Io = imopen(I, se);
    Ie = imerode(I, se);
    Iobr = imreconstruct(Ie, I);
    Ioc = imclose(Io, se);
    Iobrd = imdilate(Iobr, se);
    Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
    Iobrcbr = imcomplement(Iobrcbr);
    fgm = imregionalmax(Iobrcbr);
    se2 = strel(ones(5,5));
    fgm2 = imclose(fgm, se2);
    fgm3 = imerode(fgm2, se2);
    fgm4 = bwareaopen(fgm3, 20);
    bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
    D = bwdist(bw);
    DL = watershed(D);
    bgm = DL == 0;
    gradmag2 = imimposemin(gradmag, bgm | fgm4);
    L = watershed(gradmag2);
    

    Step 2: take the mean pixel value of of each region using regionprops:

    stats = regionprops(L,I,'MeanIntensity')
    

    Does that answer your question?

    0 comments

    Contact us at files@mathworks.com