Extract values from colormap
Afficher commentaires plus anciens
Hi everyone. I have an image where each pixel has a specific color. Each color represents a range for values, let's say: brown (value from 0 to 0.3), yellow (from 0.3 to 0.6) and green (from 0.6 to 0.9). The idea is to extract the corresponding value depending on the color for each pixel. Therefore, what I did was: Load the image using imread or readgeoraster, create a colormap. What I should do next is to define a range of values for every color and then extract the corresponding values.
% Load the image
[RasterName,RasterPath]=uigetfile('.tif','Select file');
[A,R]=readgeoraster([RasterPath,RasterName]);
p=R.ProjectedCRS;
[x,y]=worldGrid(R);
[lat,lon]=projinv(p,x,y);
InfoRaster=geotiffinfo([RasterPath,RasterName]);
RR=InfoRaster.GeoTIFFTags.GeoKeyDirectoryTag;
% Create a colormap
c1=[183,119,5]/255;
c2=[242,242,0]/255;
c3=[214,225,0]/255;
c4=[193,211,0]/255;
c5=[172,196,0]/255;
c6=[150,181,0]/255;
c7=[129,167,0]/255;
c8=[108,152,0]/255;
c9=[87,138,0]/255;
c10=[66,123,0]/255;
c11=[44,108,0]/255;
c12=[23,94,0]/255;
cmap=createcolormap(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12);
% Define range of values for every color
color_range_1=[183,119,5,255,0.00,0.10];
color_range_2=[242,242,0,255,0.11,0.20];
color_range_3=[214,225,0,255,0.21,0.30];
color_range_4=[193,211,0,255,0.31,0.40];
color_range_5=[172,196,0,255,0.41,0.50];
color_range_6=[150,181,0,255,0.51,0.60];
color_range_7=[129,167,0,255,0.61,0.70];
color_range_8=[108,152,0,255,0.71,0.80];
color_range_9=[87,138,0,255,0.81,0.90];
color_range_10=[66,123,0,255,0.91,1.00];
color_range_11=[44,108,0,255,1.01,1.10];
color_range_12=[23,94,0,255,1.11,1.20];
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Color and Styling dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!