non-green extraction problem from image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I'm trying to extract non-green from images, however It fails and does not give me a proper result. Do you know the reason? Why does it result with non-proper image? Thanks a lot.
Please see below orjinal image and result, also my matlab code.
orjinal and segmented image:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148744/image.jpeg)
my code:
al1 = imread('image');
tex=single(al1);
%
r=single(al1(:,:,1));
g=single(al1(:,:,2));
b=single(al1(:,:,3));
ExGreen=2*g-r-b;
ExRed=1.4*r-g-b;
dev=imsubtract(ExGreen,ExRed);
% otsu thresholding
thres_level = multithresh(dev); % automatic thresholding
%b_w = im2bw(dev,thres_level);
seg_I = imquantize(dev,thres_level);
%
RGB = label2rgb(seg_I,'gray');
RGB2 = single(bwareaopen(RGB,1000));
% remove the only background
BW = RGB2(:,:,1);
BW = uint8(imfill(BW,'holes'));
leaves_only = al1;
for a = 1:3
leaves_only(:,:,a) = leaves_only(:,:,a).*BW;
end
figure;
axis off
title('RGB Segmented Image')
k=imfuse(al1, leaves_only,'montage');
imshow(k)
0 Kommentare
Antworten (2)
Image Analyst
am 3 Sep. 2015
Try the Color Thresholder app on the Apps tab.
Or else see my color segmentation tutorials in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
0 Kommentare
Image Analyst
am 3 Sep. 2015
Try the attached m-file where I extract the non-green parts.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178283/image.jpeg)
3 Kommentare
Image Analyst
am 5 Sep. 2015
You're welcome. I just came back here because I noticed you have not marked it as Accepted. Are we done now, or do you still need help?
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!