필터 지우기
필터 지우기

how can I show different values of the image in different colors?

조회 수: 2 (최근 30일)
nirit
nirit 2016년 10월 10일
편집: Massimo Zanetti 2016년 10월 10일
I have a gray scale image with values that differ between 0 and 255. I want to show value 0 as black , value 255 as white, value between 1 to 100 as red, and so on. how can I do that , without changing the image values?

채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 10월 10일
Here it is how to remap a grey scale image into color image by selecting gray values intervals:
%original grayscale image
A=rgb2gray(imread('peppers.png'));
figure; imshow(A);
% 0->black 1:100->red 101-254->green 255->white
cmap = [0,0,0;1,0,0;0,1,0;1,1,1];
%remap original image to indeces 1,2,3,4
B=zeros(size(A));
B(A==0)=1;
B(1<=A & A<=100)=2;
B(101<=A & A<=254)=3;
B(A==255)=4;
%define color image by remapping
RGB = ind2rgb(B,cmap);
%remapped image
figure; imshow(RGB);
  댓글 수: 2
nirit
nirit 2016년 10월 10일
Can this be done without changing the pixels value? I want to be able to look at the original values using 'impixelinfo', but at the same time to see colors.
Massimo Zanetti
Massimo Zanetti 2016년 10월 10일
편집: Massimo Zanetti 2016년 10월 10일
Uh, I got your point. Yes you can do it by direct mapping of the image values into a your custom colormap. Your colormap will be a 256x3 matrix where RAW index 1 to index 256 map the colors of grayscale image values:
A=rgb2gray(imread('peppers.png'));
% 0->black 1:100->red 101-254->green 255->white
cmap=zeros(256,3);
cmap(2:101,:)=repmat([1,0,0],100,1);
cmap(102:255,:)=repmat([0,1,0],154,1);
cmap(end,:)=[1,1,1];
%show
img=imshow(A);
img.CDataMapping='direct';
colormap(cmap);
impixelinfo
In the pixel info string, < xxx > is the value of the gray pixel and [r g b] is the value of the color. :)

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

추가 답변 (0개)

카테고리

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