extracting leaf from background

6 Ansichten (letzte 30 Tage)
mehmet oztu
mehmet oztu am 27 Aug. 2015
Beantwortet: Ahmed raafat am 22 Jan. 2022
Hello,
after I applied watershed segmentation, I want to extract remained leaf from image,and only I want to get without background like image-2. Please can you help me. Thanks a lot. I attach below also my code.
image-1: after watershed segmentation(colored version)
image-2:image to be
Code:
% I -- intensity image
% Gmag -- gradient mag.
se = strel('disk', 30);
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I);
figure
imshow(Iobr), title('Opening-by-reconstruction (Iobr)')
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
figure
imshow(Iobrcbr), title('Opening-closing by reconstruction (Iobrcbr)')
fgm = imregionalmax(Iobrcbr);
figure
imshow(fgm), title('Regional maxima of opening-closing by reconstruction (fgm)')
% modify area
I2 = I;
I2(fgm) = 255;
figure
imshow(I2), title('Regional maxima superimposed on original image (I2)')
se2 = strel(ones(10,10));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 100);
I3 = I;
I3(fgm4) = 255;
figure
imshow(I3)
title('Modified regional maxima superimposed on original image (fgm4)')
% background markers
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
figure
imshow(bw), title('Thresholded opening-closing by reconstruction (bw)')
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
figure
imshow(bgm), title('Watershed ridge lines (bgm)')
gradmag2 = imimposemin(Gmag, bgm | fgm4);
L = watershed(gradmag2);
I4 = I;
I4(imdilate(L == 0, ones(3, 3)) | bgm | fgm4) = 255;
figure
imshow(I4)
title('Markers and object boundaries superimposed on original image (I4)')
Lrgb = label2rgb(L, 'jet', 'w', 'shuffle');
figure
imshow(Lrgb)
title('Colored watershed label matrix (Lrgb)')
figure
imshow(I)
hold on
himage = imshow(Lrgb);
himage.AlphaData = 0.3;
title('Lrgb superimposed transparently on original image')
%%Area selection
clc;
%L = labelmatrix(L);
props = regionprops(L);
[~,ind] = max([props.Area]);
imshow(labelmatrix == ind);

Antworten (3)

waqar ismail
waqar ismail am 4 Feb. 2018
Bearbeitet: waqar ismail am 4 Feb. 2018
you should use the following tutorial and before applying the water threshold you have to take a bit command on it.
<https://stackoverflow.com/questions/10284331/watershed-segmentation-algorithm-for-segmenting-occluded-leaves-in-matlab flow.com/questions/10284331/watershed-segmentation-algorithm-for-segmenting-occluded-leaves-in-matlab water threshold>

waqar ismail
waqar ismail am 4 Feb. 2018
i need dataset relate to this image and segmentation code.it is part of my project.. please send it to waqar.ismail001@gmail.com

Ahmed raafat
Ahmed raafat am 22 Jan. 2022
why don't you play on green histogram
clc;clear;close all
I=imread('image_0068.jpg');
[bincount,binloc]=hist(double(I(:,:,3)),256);
% plot(binloc,bincount)
m=sum(bincount.*binloc)/sum(bincount);
Ig=rgb2gray(I);
msk=I(:,:,3)<=m-10;
msk=bwareaopen(msk,250);
msk3=cat(3,msk,msk,msk);
Icrop=immultiply(I,msk3);
imshowpair(I,Icrop,'montage')
this was my result

Community Treasure Hunt

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

Start Hunting!

Translated by