How do I assign specific RGB colors to specific numbers in a matrix - and display?
12 views (last 30 days)
Show older comments
I am trying to create a color file from a text/matrix file consisting of numbers. How do I assign specific RGB colors to specific numbers?
1 Comment
Answers (1)
Image Analyst
on 14 Apr 2014
Let's assume your text file is a 2D array of integer numbers in the range 0-255. Use something like improtdata() or csvread() to get it into a uint8 array. Then to associate each number, make a lookup table. If you want a "standard" one, you can do
myColorMap = jet(256); % or autumn or hot or winter or whatever one you want.
Then you can either display it with a pseudocolor look up table:
imshow(yourImage);
colormap(myColorMap);
colorbar;
or you can create your own colormap if you want something specific. It's a 256 row by 3 column array with each number in it being between 0 and 1 for R, G, and B. E.g. to make gray level 0 blue:
myColorMap(1,:) = [0, 0, 1]; % Make gray level 0 be blue.
Or you can convert the indexed image into a true full color RGB image:
rgbImage = ind2rgb(yourImage, myColorMap);
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!