|
@@ -11,90 +11,87 @@ namespace bbiwarg.Images
|
|
{
|
|
{
|
|
class DepthImage
|
|
class DepthImage
|
|
{
|
|
{
|
|
- private int width;
|
|
|
|
- private int height;
|
|
|
|
- private Image<Gray, Int16> image;
|
|
|
|
- private Int16 minDepth;
|
|
|
|
- private Int16 maxDepth;
|
|
|
|
|
|
+ public Image<Gray, Int16> Image { get; private set; }
|
|
|
|
+ public int Width { get { return Image.Width; } }
|
|
|
|
+ public int Height { get { return Image.Height; } }
|
|
|
|
+ public Int16 MinDepth { get; private set; }
|
|
|
|
+ public Int16 MaxDepth { get; private set; }
|
|
|
|
|
|
- public DepthImage(int width, int height, Image<Gray, Int16> image) {
|
|
|
|
- this.width = width;
|
|
|
|
- this.height = height;
|
|
|
|
- this.image = image;
|
|
|
|
|
|
+ public DepthImage(Image<Gray, Int16> image)
|
|
|
|
+ {
|
|
|
|
+ this.Image = image;
|
|
|
|
|
|
//smooth
|
|
//smooth
|
|
- this.image = image.SmoothMedian(3);
|
|
|
|
|
|
+ this.Image = image.SmoothMedian(3);
|
|
|
|
|
|
//threshold min&maxDepth
|
|
//threshold min&maxDepth
|
|
- minDepth = findMinDepth();
|
|
|
|
- maxDepth = (Int16) (minDepth + 200);
|
|
|
|
- thresholdDepth(minDepth, maxDepth);
|
|
|
|
|
|
+ MinDepth = findMinDepth();
|
|
|
|
+ MaxDepth = (Int16)(MinDepth + 200);
|
|
|
|
+ thresholdDepth(MinDepth, MaxDepth);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public Int16 getDepthAt(Point point) {
|
|
|
|
|
|
+ public Int16 getDepthAt(Point point)
|
|
|
|
+ {
|
|
return getDepthAt(point.X, point.Y);
|
|
return getDepthAt(point.X, point.Y);
|
|
}
|
|
}
|
|
|
|
|
|
- public Int16 getDepthAt(int x, int y) {
|
|
|
|
- return image.Data[y, x, 0];
|
|
|
|
|
|
+ public Int16 getDepthAt(int x, int y)
|
|
|
|
+ {
|
|
|
|
+ return Image.Data[y, x, 0];
|
|
}
|
|
}
|
|
|
|
|
|
- public void setDepthAt(Point point, Int16 depth) {
|
|
|
|
|
|
+ public void setDepthAt(Point point, Int16 depth)
|
|
|
|
+ {
|
|
setDepthAt(point.X, point.Y, depth);
|
|
setDepthAt(point.X, point.Y, depth);
|
|
}
|
|
}
|
|
|
|
|
|
- public void setDepthAt(int x, int y, Int16 depth) {
|
|
|
|
- image.Data[y, x, 0] = depth;
|
|
|
|
|
|
+ public void setDepthAt(int x, int y, Int16 depth)
|
|
|
|
+ {
|
|
|
|
+ Image.Data[y, x, 0] = depth;
|
|
}
|
|
}
|
|
|
|
|
|
- public float getRelativeDepthAt(Point point) {
|
|
|
|
|
|
+ public float getRelativeDepthAt(Point point)
|
|
|
|
+ {
|
|
return getRelativeDepthAt(point.X, point.Y);
|
|
return getRelativeDepthAt(point.X, point.Y);
|
|
}
|
|
}
|
|
|
|
|
|
- public float getRelativeDepthAt(int x, int y) {
|
|
|
|
- float minMaxInterval = Math.Max(maxDepth - minDepth, 1);
|
|
|
|
- return (getDepthAt(x, y)-minDepth) / minMaxInterval;
|
|
|
|
|
|
+ public float getRelativeDepthAt(int x, int y)
|
|
|
|
+ {
|
|
|
|
+ float minMaxInterval = Math.Max(MaxDepth - MinDepth, 1);
|
|
|
|
+ return (getDepthAt(x, y) - MinDepth) / minMaxInterval;
|
|
}
|
|
}
|
|
|
|
|
|
- public Int16 getMinDepth() {
|
|
|
|
- return minDepth;
|
|
|
|
|
|
+ public Int16 getMinDepth()
|
|
|
|
+ {
|
|
|
|
+ return MinDepth;
|
|
}
|
|
}
|
|
|
|
|
|
- public Int16 getMaxDepth() {
|
|
|
|
- return maxDepth;
|
|
|
|
|
|
+ public Int16 getMaxDepth()
|
|
|
|
+ {
|
|
|
|
+ return MaxDepth;
|
|
}
|
|
}
|
|
|
|
|
|
- public int getWidth() {
|
|
|
|
- return width;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int getHeight() {
|
|
|
|
- return height;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Image<Gray, Int16> getImage() {
|
|
|
|
- return image;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Int16 findMinDepth() {
|
|
|
|
- minDepth = Int16.MaxValue;
|
|
|
|
- for (int x = 0; x < width; ++x)
|
|
|
|
|
|
+ private Int16 findMinDepth()
|
|
|
|
+ {
|
|
|
|
+ MinDepth = Int16.MaxValue;
|
|
|
|
+ for (int x = 0; x < Width; ++x)
|
|
{
|
|
{
|
|
- for (int y = 0; y < height; ++y)
|
|
|
|
|
|
+ for (int y = 0; y < Height; ++y)
|
|
{
|
|
{
|
|
Int16 depth = getDepthAt(x, y);
|
|
Int16 depth = getDepthAt(x, y);
|
|
- if (depth < minDepth)
|
|
|
|
- minDepth = depth;
|
|
|
|
|
|
+ if (depth < MinDepth)
|
|
|
|
+ MinDepth = depth;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return minDepth;
|
|
|
|
|
|
+ return MinDepth;
|
|
}
|
|
}
|
|
|
|
|
|
- private void thresholdDepth(Int16 min, Int16 max) {
|
|
|
|
- for (int x = 0; x < width; ++x)
|
|
|
|
|
|
+ private void thresholdDepth(Int16 min, Int16 max)
|
|
|
|
+ {
|
|
|
|
+ for (int x = 0; x < Width; ++x)
|
|
{
|
|
{
|
|
- for (int y = 0; y < height; ++y)
|
|
|
|
|
|
+ for (int y = 0; y < Height; ++y)
|
|
{
|
|
{
|
|
Int16 depth = getDepthAt(x, y);
|
|
Int16 depth = getDepthAt(x, y);
|
|
if (depth > max || depth < min)
|
|
if (depth > max || depth < min)
|