我有一个从0到255的int范围。
然后,我想为该值指定一种颜色,类似于kinect深度视图。
我该怎么做才能将int映射到颜色?
我正在使用Java及其标准库。
答案 0 :(得分:1)
我发现这解决了我的问题...
我没有找到除硬编码之外的其他方法,如果有人有更好的方法,请告诉我。
http://www.pages.drexel.edu/~nk752/depthMapTut.html#Step%204
for (row = 0; row < H; row++) {
for (col = 0; col < W; col++) {
i = (unsigned long)(row*3*W + col*3);
tempDepth = depthMapReal[row / increment][col / increment];
if(tempDepth < 43){
depthRed = tempDepth * 6;
depthGreen = 0;
depthBlue = tempDepth * 6;
}
if(tempDepth > 42 && tempDepth < 85){
depthRed = 255 - (tempDepth - 43) * 6;
depthGreen = 0;
depthBlue = 255;
}
if(tempDepth > 84 && tempDepth < 128){
depthRed = 0;
depthGreen = (tempDepth - 85) * 6;
depthBlue = 255;
}
if(tempDepth > 127 && tempDepth < 169){
depthRed = 0;
depthGreen = 255;
depthBlue = 255 - (tempDepth - 128) * 6;
}
if(tempDepth > 168 && tempDepth < 212){
depthRed = (tempDepth - 169) * 6;
depthGreen = 255;
depthBlue = 0;
}
if(tempDepth > 211 && tempDepth < 254){
depthRed = 255;
depthGreen = 255 - (tempDepth - 212) * 6;
depthBlue = 0;
}
if(tempDepth > 253){
depthRed = 255;
depthGreen = 0;
depthBlue = 0;
}
*(m_destinationBmp + i) = depthBlue;
*(m_destinationBmp + i + 1) = depthGreen;
*(m_destinationBmp + i + 2) = depthRed;
}
}
break;
}