Create an RGB image from an elevation array.

조회 수: 5 (최근 30일)
Chandler Slater
Chandler Slater 2020년 12월 11일
답변: Image Analyst 2020년 12월 12일
I need to rite a script to read the elevation data set. Then create an RGB image the same size as the elevation array. Then color all points above sea level (elev > 0) black, and color all points below sea level blue.

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 12일
편집: KALYAN ACHARJYA 2020년 12월 12일
Lets suppose 'data' is the the elevation data set
data= randi([-5,5],[50,50]); % Example
%....................^the array may have any dimention
% Fore all data>0 to 0, which result black pixels
data(data>=0)=0;
% Make all data<0 to blue pixel Blue=[R=0,G=0,B=139]
% Create three Plane for RGB
R=data;G=data;B=data;
R(data<0)=0; G(data<0)=0; B(data<0)=139;
rgbImage=cat(3,R,G,B);
figure,imshow(rgbImage,[]);

Image Analyst
Image Analyst 2020년 12월 12일
If you want to use a colormap instead of an RGB image like KALYAN showed you, you can do this, though I admit it's tricker/harder than the RGB version:
% Create sample data between -500 and +2000 meters.
seaDepths = -500 + 2000 * rand(40, 60);
% Create colormaps. Choose one of the two options below and command the other one out.
% Option 1 : Create colormap with pure 100% solid blue everywhere
% except on one row that will be used to color map for data > 0
cmap = [zeros(256,1), zeros(256,1), ones(256, 1)]
cmap(end,:) = 0; % Black.
% Option 2 : Create colormap with a gradient from blue at -500 to black at 0
cmap = [zeros(256,1), zeros(256,1), (255:-1:0)'] / 255
% Display the image with the colormap we created.
imshow(seaDepths, [], 'ColorMap', cmap);
axis('on', 'image');
caxis([-500, 0]);
colorbar
impixelinfo; % Let user mouse around and see the original depth value.
% Maximize figure window.
g = gcf;
g.WindowState = 'maximized';

카테고리

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