Replace the white region in an binary image with Green ? and black colour unaffected

조회 수: 2 (최근 30일)
I Will read my input image as binary.(may be logical or uint8). The output must be Image with green colours in white region and black remains the same.

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 8월 28일
편집: Joseph Cheng 2014년 8월 28일
you can define the colormap used. here is a quick example
point3d = imread('pears.png');
value = rgb2gray(point3d);
BIN = value>124;
cmap = [ 0 0 0;0 1 0];
imagesc(BIN),colormap(cmap)
so since i have a binary i know the green area is the logical 1 and black 0. if it is not logical then you'll have to scale the colormap to the values of white and black.
  댓글 수: 2
Anand
Anand 2014년 8월 28일
I accept your answer.. but I need to store that last output ie Image with green color.. I tried using imwrite(BIN,'new.jpg').. but its only writing the previous black and white image.. any help on this...?
Joseph Cheng
Joseph Cheng 2014년 8월 28일
Ah then you'll have to go with Image Analyst's answer.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 8월 28일
Anand, if you want an RGB image instead of a pseudocolored logical image (with values of 0 and 1) then you need to do this:
grayImage = uint8(255 * BIN); % BIN is from Joseph's code.
blackImage = zeros(size(grayImage), 'uint8');
rgbImage = cat(3, blackImage , grayImage, blackImage); % Only green channel is non-zero.
imshow(rgbImage);
imwrite(rgbImage, fullFileName);

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by