![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/197986/image.png)
how to mask the image and keep only one color "green channel"?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Oman Wisni
el 25 de Sept. de 2018
Comentada: Oman Wisni
el 27 de Sept. de 2018
Hi, here I have one photo and the code, please anyone help me to fix my code, I want to mask the binary with the RGB.
% Extract the individual red, green and blue color channel
redChannel = hasilcontrast(:,:,1);
greenChannel = hasilcontrast(:,:,2);
blueChannel = hasilcontrast(:,:,3);
% Create the mask
mask = cast(green, class(hasilcontrast));
redmask = redChannel.*mask;
greenmask = greenChannel.*mask;
bluemask = blueChannel.*mask;
% segmentasi
maskRGBimage = cat(3,redmask, greenmask, bluemask);
I not get the result, how I do to show the image. please help me sir
3 comentarios
Respuesta aceptada
Image Analyst
el 26 de Sept. de 2018
I've done this so many times I lost track, and some time back decided to make a demo of it. Leaf, fruit, money, handwriting, leaf, fruit, money, handwriting, everyone wants to segment a leaf, fruit, money, or handwriting. Click on the tag "leaf" on the right hand side of this page. See attached demo.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196521/image.png)
11 comentarios
Image Analyst
el 27 de Sept. de 2018
If you get holes in your leaf, and don't want them, you can call
mask = imfill(mask, 'holes');
Más respuestas (1)
Akira Agata
el 26 de Sept. de 2018
Hi Oman-san,
Thank you for your prompt reply. The following is the code to generate the posted figure. I hope this will be some help for your research!
% Read the image
I = imread('base1.bmp');
% Create a mask based on a green channel of the image
BWmask = ~imbinarize(I(:,:,2));
BWmask = imfill(BWmask,'holes');
% Create a masked RGB image
Imasked = immultiply(I,repmat(BWmask,[1 1 3]));
% Show the results
figure
subplot(2,2,1)
imshow(I)
title('Original','FontSize',12)
subplot(2,2,2)
imshow(BWmask)
title('Mask','FontSize',12)
subplot(2,2,3)
imshow(Imasked)
title('Masked RGB','FontSize',12)
1 comentario
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!