필터 지우기
필터 지우기

Replace pixel value 1 to rgb colour

조회 수: 2 (최근 30일)
Lidank Abiel
Lidank Abiel 2014년 12월 22일
편집: Lidank Abiel 2014년 12월 22일
I try to replace pixel == 1 in b/w image to rgb image, but it's look like not success 100%. How to make it to good result based on this code :
for i = 1 :size(a) for j = 1: size(a) if c(i,j) == 0 a(i,j) = 0;
where a is rgb image, c is binary image.
this is my result :

채택된 답변

Image Analyst
Image Analyst 2014년 12월 22일
Try this:
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));
mask is what you called "c" and rgbImage is what you called "a". I put the output into a new image but you could assign it to the same "a" image if you wanted to. I really strongly suggest you use descriptive variable names in your code to make it more maintainable and understandable. There is nothing worse than having to look at someone's code that's an alphabet soup of dozens of single letter variable names. It's very hard to keep track of what variable represents what.
  댓글 수: 3
Image Analyst
Image Analyst 2014년 12월 22일
It multiplies each color plane of the RGB image by the 2D mask image. To do a multiplication the mask needs to be of the same type. Masks are usually logical but to multiply by a uint8 image, it needs to be cast from a logical to a uint8.
Lidank Abiel
Lidank Abiel 2014년 12월 22일
편집: Lidank Abiel 2014년 12월 22일
It work. Thx Image Analyst
This is my result now :

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by