创建深度直方图而不使用太多的箱

时间:2014-08-05 01:19:09

标签: c# histogram emgucv color-depth perceptual-sdk

我想创建图像的深度直方图,以查看深度值的分布如何变化。但我不知道该怎么做,因为有太多可能的深度,并且计算每一个都会导致带有大量箱子的直方图。像(480 * 640)图像中的307,200个箱子一样。

在以下网页中:

http://www.i-programmer.info/programming/hardware/2714-getting-started-with-microsoft-kinect-sdk-depth.html?start=2

他们将深度值的数量除以4,然后对数据执行位移调整以创建合理的显示效果:

for (int i = 0; i < PImage.Bits.Length; i += 2)
{
 temp= (PImage.Bits[i+1]<<8 |
               PImage.Bits[i])& 0x1FFF ;
 count[temp >> 2]++;
 temp <<= 2;
 PImage.Bits[i] = (byte) (temp & 0xFF);
 PImage.Bits[i + 1] = (byte) (temp >> 8);
}

我理解他们所做的操作,但我不明白这种方法如何将数据缩小到1/4

那么,如何在不使用过多垃圾箱的情况下显示该信息以创建合理的显示效果?

有什么想法吗?

致以最诚挚的问候,

1 个答案:

答案 0 :(得分:1)

这部分解释了它:

  

有太多可能的深度,并计算每个深度   在具有大量箱子的直方图中,我们将距离除以4   这意味着我们只需要四分之一的箱子:

int[] count = new int[0x1FFF / 4 +1];

通过将深度值除以4,您可以通过降低测量不同深度的分辨率来减少容器数量。这允许count数组的大小小4倍。

根据您的评论

  

与(480 * 640)图像中的307,200个像素一样。

我认为你可能误解了直方图是什么。屏幕尺寸与垃圾箱数量无关。您只能在整个场景中测量每个不同深度级别的一个数据点,它们根本不与屏幕位置相关。


代码说明:

for (int i = 0; i < PImage.Bits.Length; i += 2)
{
    //gets the depth value by combining 2 adjacent bytes from the data into 
    //a 2 byte value and trims the value to a max of 8191 (2^13)
    temp= (PImage.Bits[i+1]<<8 |
                  PImage.Bits[i])& 0x1FFF;

    //divides the value by 4 and increments counter for that depth value
    count[temp >> 2]++;

    //multiply depth value by 4, trimming off the lower bits, I assume this  
    //makes the depth differences more obvious when we write the new depth 
    //value back to the image data
    temp <<= 2;

    //write the depth value back to the image buffer
    PImage.Bits[i] = (byte) (temp & 0xFF);
    PImage.Bits[i + 1] = (byte) (temp >> 8);
}