removing Non-green background from image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
mehmet oztu
am 22 Aug. 2015
Kommentiert: Madhulatha K N
am 11 Jul. 2018
hello,
I'm trying to eliminate non-green background from an image. You can see my below codes, I think It's working. But the thing is, after this process (or any other suggestion), I want to keep leaves as exactly in original photos without background.
Many thanks in advance.
Orjinal photo:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148339/image.jpeg)
I want to get like this(you can see background is black, means it's removed):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148340/image.jpeg)
al1 = imread('23.JPG');
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,1); % automatic thresholding
seg_I = imquantize(dev,thres_level);
RGB = label2rgb(seg_I,'gray');
RGB2 = single(bwareaopen(RGB,1000000)); %clean the areas smaller than 1million pixels
k=imfuse(al1, RGB2,'montage'); %composite of 2images
imshow(k)
1 Kommentar
Madhulatha K N
am 11 Jul. 2018
thank you for posting the question. it is helping me with a project where I need to do the same as you are doing. But what are ExGreen nd ExRed variables in the code? what are they being calculated for?
Akzeptierte Antwort
Jon
am 23 Aug. 2015
Try this:
BW = RGB2(:,:,1);
BW = uint8(imfill(BW,'holes'));
leaves_only = al1;
for a = 1:3
leaves_only(:,:,a) = leaves_only(:,:,a).*BW;
end
imshow(leaves_only)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!