Putting color on binary image

조회 수: 24 (최근 30일)
Ravin Rayeok
Ravin Rayeok 2020년 2월 28일
댓글: Ravin Rayeok 2020년 2월 28일
Hello!
Need a hand here, I want to color my binary image resulting from thresholding of rgb image.
How to do it? let's say, black to blue and white to green.

채택된 답변

Guillaume
Guillaume 2020년 2월 28일
편집: Guillaume 2020년 2월 28일
Here's an easy way, assuming that your start image is indeed a binary image (i.e a 2D matrix with values 0 or 1):
%binaryimage: 2D matrix of 0s and 1s
map = [0 0 1; ...replacement colour for black as a RGB triplet, fully saturated blue in this case
0 1 0]; %replacement colour for white as a RGB triplet, fully saturated green in this case
colouredimage = map(binaryimage + 1 + cat(3, 0, 2, 4));
imshow(colouredimage); %to check
edit: Actually an even easier way, and certainly easier to understand, is with
map = [0 0 1; ...replacement colour for black as a RGB triplet, fully saturated blue in this case
0 1 0]; %replacement colour for white as a RGB triplet, fully saturated green in this case
colouredimage = label2rgb(binaryimage + 1, map);
assuming you have the image processing toolbox.
  댓글 수: 1
Ravin Rayeok
Ravin Rayeok 2020년 2월 28일
Ah i see, thanks a lot!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by