How to use Watershed function to find multiple regions in a 2D array?

조회 수: 2 (최근 30일)
Jiaxi Hu
Jiaxi Hu 2016년 9월 14일
편집: Jiaxi Hu 2016년 9월 14일
Hi There,
  • I'm a newbie to Matlab and I'm wondering if there is a better or easier way to find multiple peak regions (I understand watershed follows the idea to find sinks so I just multiplied the data by -1). I'm following the method from link Marker-Controlled Watershed Segmentation Here is my code :
rgb = imread('vil_matlab_test.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);
I2 = I;
I2(fgm) = 255;
se2 = strel(ones(5,5));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 20);
I3 = I;
I3(fgm4) = 255;
bw = imbinarize(Iobrcbr);
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
figure
The input figure looks like :
I'm expecting to find at least two regions, but the result looks like :
Can anyone tell me how to correct this? Or is there other better way to do this? Thanks!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by