Create an RGB image from an elevation array.

3 ビュー (過去 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 Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by