How to generate colormap for specific matrix?

조회 수: 27 (최근 30일)
AS
AS 2021년 7월 29일
편집: Dave B 2021년 7월 29일
I have matrix with values and corresponding index number or class number. I want to generate a colormap based on the values of the matrix not the on index number. I have attached a file, where first column indicates values and 2nd column is class number. I am able to do it based on the class number. But, I want to generate a colomap based on the values provided in 1st column in myfile. Means if these values [ 315.2184 315.828 323.7528 323.9052 338.3832 ] are present in an array it will be red color and so on.
Please suggest me as I am unable to do that. Thank you.

채택된 답변

Dave B
Dave B 2021년 7월 29일
편집: Dave B 2021년 7월 29일
I'm not 100% sure I understand the quesiton but here's how I interpreted it:
There's a map that goes from a set of raw values to one of four numbers, and we want to apply that map to a separate set of raw values.
Here's some test data to simulate what's in your excel file:
vals = rand(10,1); % 10 values
classes = randi(4,10,1); % each value is one of four random classes
Here's an example 25x25 image to be mapped:
rawimage=vals(randi(10,25,25))
Here's rawimage converted to classes using the map. Note that using 'nearest' means that if there was something in vals that's not in classes, but in between two vals that are in classes, it'll use the nearest class:
mappedimage=interp1(vals, classes, rawimage, 'nearest')
Call image, and set an appropriate colormap to view. Note that image will use CDataMapping='direct' by default, which means 1 corresponds to the first value in the colormap, 2 to the second value, etc.
image(mappedimage)
colormap lines
Alternatively, to get the color values and not display them:
b=ind2rgb(mappedimage,lines(4));
You might also check out imquantize in the image processing toolbox, it let's you input the boundaries between categories and will do the rest for you.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by