2012-03-04 35 views
1

我已經從0到255之間地圖INT [0255]不同的顏色

我然後要顏色分配給值,有點像Kinect的深度視圖一個INT範圍。

我該怎麼做才能將int映射到顏色?

我正在使用Java及其標準庫。

+0

告訴我們您的編程環境。語言?圖書館?操作系統? – 2012-03-04 19:35:55

+0

我更新了這些信息,謝謝! – 2012-03-04 19:36:49

回答

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; 
}