
Create an RGB image from an elevation array.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (2)
KALYAN ACHARJYA
le 12 Déc 2020
Modifié(e) : KALYAN ACHARJYA
le 12 Déc 2020
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,[]);

0 commentaires
Image Analyst
le 12 Déc 2020
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';
0 commentaires
Voir également
Catégories
En savoir plus sur Color and Styling dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!