创建深度直方图,不使用太多的箱子
本文关键字:太多 箱子 深度 直方图 创建 | 更新日期: 2023-09-27 18:16:18
我想创建一个图像的深度直方图,看看深度值的分布是如何变化的。但我不知道怎么做,因为有太多可能的深度,计算每一个深度会导致一个有很多箱子的直方图。例如,从(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的
那么,我如何在不使用太多箱子的情况下显示这些信息来创建一个合理的显示呢?
任何想法?
问好,
这部分解释:
有太多可能的深度,计数每一个都会导致在有很多箱子的直方图中我们把距离除以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);
}