how to extract rgb color image from surface height colormap

조회 수: 3 (최근 30일)
Itzik Ben Shabat
Itzik Ben Shabat 2015년 3월 11일
댓글: Itzik Ben Shabat 2015년 3월 11일
Hi all, I wrote the code attached below. what i wish to do now (and not sure how) is create an RGB image from the colors that are defined by the Z values. so lets say that in the given example the color at each point will translate to a pixel then i will have a 61X61 RGB color image. how can i do that ?
[X,Y] = meshgrid(-3:0.1:3,-3:0.1:3);
Z=peaks(X,Y);
%Geneating the colors for the colormap
colors=[0,0.6,1;
0,0.6,1;
0.95,0.95,0.95;
0.953,0.64,0.375;
0,1,0;
1,1,1;
1,1,1];
colors_number=size(colors,1);
colors_interp = interp1(1:colors_number,colors,1:0.1:colors_number);
% Draw the surface
h=surf(X,Y,Z,'edgecolor','none');
colormap(colors_interp);

채택된 답변

Guillaume
Guillaume 2015년 3월 11일
See the tip section of caxis for an explanation of how matlab maps the Z values to a colour map index. So:
mapbounds = caxis;
numcolours = size(colors_interp, 1);
mapindex = fix((Z-mapbounds(1)) / (mapbounds(2) - mapbounds(1)) * numcolours) + 1;
mapindex(mapindex < 1) = 1;
mapindex(mapindex > numcolours) = numcolours;
img = ind2rgb(mapindex, colors_interp);
imshow(img);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by