Reverse Color Mapping to Numerical Scale
古いコメントを表示
I'm working with an image that contains a colormap associated with a sliding scale (e.g., numbers 0 to 14). Is there a way to convert the RGB values that I'm given to the colormap matrix? Basically I need to take a color and find its corresponding number (e.g., a certain type of red would correspond to 13).
If there is a matlab function, that would be great, but any ideas would be helpful. Thanks!
回答 (1 件)
Image Analyst
2013 年 5 月 24 日
0 投票
The image already has those values. If it's an indexed image with associated colormap, then you already know everything you need to know. What else do you need? What RGB values do you have? If you have an RGB triplet then it should be in the colormap if it occurs in the image at all. For example, the image has a value of 13, and the colormap in row 13 might be (220, 20, 50) or whatever. Or if you have (220, 20, 50) you can use ismember() to find it at row #13 in the colormap.
4 件のコメント
Image Analyst
2013 年 5 月 24 日
Katie commented:
I have the RGB values, but some of them don't match the colormap. Because the colormap is a matrix of 64 discrete values, it doesn't necessarily contain every value in the spectrum. I really need a function that takes x (in the set of integers 1,64) to the RGB values that can be extended to the interval [1,64]
Image Analyst
2013 年 5 月 24 日
Katie: Where did these RGB values come from? They're not in the colormap. And they aren't in your image because your image just has one value at each pixel, not 3 - and that value is an index into the colormap.
Katie
2013 年 5 月 24 日
Image Analyst
2013 年 5 月 24 日
編集済み: Image Analyst
2013 年 5 月 24 日
That sounds just like a regular color image. p can be either 1 for red, 2 for green, and 3 for blue. Then it sounds like you have some totally different colormap that you got somewhere and you'd like to figure out which color in the colormap is closest to each pixel. You need to check each pixel against the colormap color and find out which colormap color is closest. For example if you have 14, or 64 rows in your colormap, you'll have to calculate the Euclidean distance from the RGB color of the image to the RGB color from each row in your colormap. Does that sound like what you want to do? So let's say that pixel located at (1,1) (the upper left pixel) is closest to color #14, and pixel (1,2) is closest to color #53, and pixel (1,3) is closest to #16, and so on down to the pixel at the lower right. So essentially you're creating an indexed image using some given colormap, rather than using the optimal colormap which a function like rgb2ind() would find. Why do you want to do this? If you do, you can pass in your given colormap to rgb2ind() like this:
indexedImage = rgb2ind(rgbImage, myColorMap);
カテゴリ
ヘルプ センター および File Exchange で Color and Styling についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!