non-green extraction problem from image
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Image Analyst
2015 年 9 月 3 日
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 件のコメント
Image Analyst
2015 年 9 月 3 日
Try the attached m-file where I extract the non-green parts.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178283/image.jpeg)
3 件のコメント
Image Analyst
2015 年 9 月 5 日
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?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!