Minor modifications to the https://blog.csdn.net/huixingshao/article/details/42706699
The principle of pseudo-color processing for grayscale images is as follows:
according to the color study results, the grayscale image corresponds to red, green, blue three channels, and finally the color values of three channels are synthesized into the RGB color values that need to be displayed.
the mapping between grayscale values and three channels is shown in Figure 3, figure 4, and Figure 5:
Figure 1: Grayscale and red channel mapping relationship
Figure 2: Grayscale and green channel mapping relationship
[CPP] View Plain copy print? Vec3b greytocolormix (int val) { int r,g,b; //red if (val<128) { r = 0; } else if (val<192) { r = 255/ 64* (val-128); } else { r=255; } //green if (val<64) { g = 255/64*val; } else if (val<192) { g = 255; } else { g= -255/63* (val - 192) +255; } //blue if (val<64) { b = 255; } else if (val<128) { b = -255/63* (Val - 192) +255; } else { b=0; } Vec3b rgb; rgb[0] = b; rgb[1] = g; rgb[2] = r; return rgb; }
vec3b greytocolormix (int val)
{
int r,g,b;
Red
if (val<128)
{
r = 0;
}
else if (val<192)
{
r = 255/64* (val-128);
}
else
{
r=255;
}
Green
if (val<64)
{
g = 255/64*val;
}
else if (val<192)
{
g = 255;
}
else
{
g= -255/64* (val-192) +255;
}
Blue
if (val<64)
{
b = 255;
}
else if (val<128)
{
b = -255/64* (val-128);
}
else
{
b=0;
}
VEC3B RGB;
Rgb[0] = b;
Rgb[1] = g;
RGB[2] = r;
return RGB;
}
Figure 3: Grayscale and blue channel mapping relationship
</div>
</div>