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!