从灰度图像构建颜色条

时间:2021-09-08 22:56:19

I've an 8-bit grayscale image representing intensities. I would like to display it with color according the intensity value (to be clear,something like this http://www.matthiaspospiech.de/files/matlab/plot/pcolor/pcolor-example-simple.png).

我有一个代表强度的8位灰度图像。我想根据强度值显示颜色(要清楚,像http://www.matthiaspospiech.de/files/matlab/plot/pcolor/pcolor-example-simple.png这样)。

I tried with an HSV scale (with H in (0->85) or (85->140) or (140->255) and then go back to RGB but it seems not to work. Does any have an idea ? Here is my code: (it runs in loops on i and j, img is the grayscale image,

我尝试使用HSV刻度(H在(0-> 85)或(85-> 140)或(140-> 255)然后返回RGB但似乎不起作用。有没有想法?这里是我的代码:(它在i和j上循环运行,img是灰度图像,

grey = img[j*w+i];                                                                                             

H = (grey * 360.0) / 255 ;
X = 1-((int)abs((int)(h/60.0) % 2) - 1);

if(BETWEEN(H,0,60) || BETWEEN(H,300,360)) r = 1.0;
else if(BETWEEN(H,60,120) || BETWEEN(H,240,300)) r = X;
else r = 0;

if(BETWEEN(H,60,180)) g = 1.0;
else if(H >= 240) g = 0;
else g = X;

if(BETWEEN(H,180,300)) b = 1.0;
else if(H < 120) b = 0;
else b = X;

R = (int)(r*255.0);
G = (int)(g*255.0);
B = (int)(b*255.0);

(the final goal is to use it in a Java program with OpenImaj so if someone knows something about it, it's fine too :) )

(最终目标是在OpenImaj的Java程序中使用它,所以如果有人知道它,它也很好:))

1 个解决方案

#1


2  

Take the HSB system. Set S to 100 (full saturation). Set B to 100 (maximum brightness). I suppose your grey in in [0,255], set H to (1-(grey/255.0))*240.

采用HSB系统。将S设置为100(完全饱和)。将B设置为100(最大亮度)。我想你的灰色在[0,255],将H设置为(1-(灰色/ 255.0))* 240。

This will roughly produces something like the given picture. When grey=0, H will be 240° so blue, and when grey=255, H will be 0° so red...

这将大致产生类似给定图片的东西。当灰色= 0时,H将是240°那么蓝色,当灰色= 255时,H将是0°所以红色......

You can also modify B to obtain bright or deep colors...

你也可以修改B来获得明亮或深色......

HVB to RGB conversion can be found on the web if not available in your API.

如果您的API中没有HVB到RGB转换,可以在网上找到。

#1


2  

Take the HSB system. Set S to 100 (full saturation). Set B to 100 (maximum brightness). I suppose your grey in in [0,255], set H to (1-(grey/255.0))*240.

采用HSB系统。将S设置为100(完全饱和)。将B设置为100(最大亮度)。我想你的灰色在[0,255],将H设置为(1-(灰色/ 255.0))* 240。

This will roughly produces something like the given picture. When grey=0, H will be 240° so blue, and when grey=255, H will be 0° so red...

这将大致产生类似给定图片的东西。当灰色= 0时,H将是240°那么蓝色,当灰色= 255时,H将是0°所以红色......

You can also modify B to obtain bright or deep colors...

你也可以修改B来获得明亮或深色......

HVB to RGB conversion can be found on the web if not available in your API.

如果您的API中没有HVB到RGB转换,可以在网上找到。