필터 지우기
필터 지우기

how to mask the image and keep only one color "green channel"?

조회 수: 29 (최근 30일)
Oman Wisni
Oman Wisni 2018년 9월 25일
댓글: Oman Wisni 2018년 9월 27일
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
Oman Wisni
Oman Wisni 2018년 9월 26일
Yes, I want like that, can you show me the code? I'm sorry, I confused how I explain, but your answer is right
Oman Wisni
Oman Wisni 2018년 9월 26일
How you get the maskedRGB? Do you multiply multiply the original image with mask?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2018년 9월 26일
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.
  댓글 수: 11
Image Analyst
Image Analyst 2018년 9월 27일
If you get holes in your leaf, and don't want them, you can call
mask = imfill(mask, 'holes');
Oman Wisni
Oman Wisni 2018년 9월 27일
Yes sir, thanks.. Sir, the value 200, is that default value?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Akira Agata
Akira Agata 2018년 9월 26일
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
Oman Wisni
Oman Wisni 2018년 9월 26일
편집: Oman Wisni 2018년 9월 26일
thanks sir, you only keep green channel, I think all channel have been mask than you recombine again..
Im sorry sir, after I see your code that is not I mean. Like my code in above I want mask all channel in RGB channel, I get the mask every channel then I combine again. for mask I using multiply, and for recombine I using maskRGBimage = cat(3,redmask, greenmask, bluemask); and the result only keep green channel, I already upload the picture index.jpg, I want like that but no saturation channel.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by