Filter löschen
Filter löschen

How to take mean for watershed algorithm?

1 Ansicht (letzte 30 Tage)
john
john am 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.

Antworten (1)

Sven
Sven am 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?

Community Treasure Hunt

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

Start Hunting!

Translated by