Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMDImageProc.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __BIAS_PMDIMAGEPROC_H__
26 #define __BIAS_PMDIMAGEPROC_H__
27 
28 #include <bias_config.h>
29 #include <Base/Image/Image.hh>
30 
31 #include <Base/Image/PMDImageIO.hh>
32 #include <Geometry/Projection.hh>
33 #include <Base/Geometry/KMatrix.hh>
34 #include <Geometry/HMatrix.hh>
35 #include <Geometry/Pose.hh>
36 #include <Base/Common/CompareFloatingPoint.hh>
37 
38 
39 namespace BIAS {
40 
41  class BIASImage_EXPORT PMDImageProc
42  {
43 
44 
45  public:
46 
47  /** @brief convert a depth image such that the depth and the grey value
48  at the same pixel position belong to the same ray. The transformation
49  information is taken from the metadata. MetaDataDepth is changed
50  for the converted depth image and is identical to MetaData2D afterwards
51  @param ImgDepth is the image to convert. This image has to contain
52  depth information and is changed in size and contents.
53  @param MetaData2D this is the metadata for the 2D-image.
54  @param MetaDataDepth the metadata for the depth image. Is adapted
55  to reflect the image transformation.
56  @author Birger Streckel **/
57  static int FitDepthTo2DImage(Image<float> &ImgDepth,
58  const PMDImageMetaData &MetaData2D,
59  PMDImageMetaData &MetaDataDepth);
60 
61  static int FitDepthTo2DImage(Image<float> &ImageDepth,
62  const BIAS::Projection &proj2D,
63  const BIAS::Projection &projDepth,
64  int kernelsize=0);
65 
66 
67  static int FitModCoeffTo2DImage(Image<float> &ImgModCoeff,
68  const Image<float> &ImgDepth,
69  const PMDImageMetaData &MetaData2D,
70  PMDImageMetaData &MetaDataDepth);
71  /**
72  * \brief calculates a color image of the size of the depth image
73  * by projecting every pixel of the depth image to 3D space and projecting it back
74  * to the color image using the color image projection
75  * \param depthImage[in] : the depth imahe to use
76  * \param textureImage[in] : the original color image
77  * \param depthProj[in] : projection corresponding to depthImage
78  * \param textureProj[in] : projection corresponding to textureImage
79  * \param newColorImage[out]: calculated new color image, same size as depthImage
80  * \author ischiller
81  * \date 08/2010
82  */
83  static void Fit2DToDepthImage(Image<float> &depthImage,
84  Image<unsigned char>& textureImage,
85  Projection& depthProj,Projection& textureProj,
86  Image<unsigned char>& newColorImage);
87 
88  static KMatrix KFromMeta(const PMDImageMetaData &MetaData);
89  static Pose PoseFromMeta(const PMDImageMetaData &MetaData);
90  static PMDImageMetaData MetaFromPoseAndK(const Pose &Po,
91  const KMatrix &K, int width,
92  int height, int channels);
93 
94  /**
95  * \brief use to limit the depth spread to a certain range around
96  * the
97  */
98  static void LimitDepthSpread(BIAS::Image<float>& depthImage,
99  float maxDeviation);
100 
101  /** Give the standard deviation for a pixel in the depth image.
102  * Measurement precision polynome was taken from:
103  * M.Stommel K.-D.Kuhnert "Fusion of Stereo-Camera and PMD-Camera
104  * Data for Real-Time Suited Precise 3D Environment Reconstruction"
105  * @returns the sigma of the pixel depth depending on the precision
106  * formula and the surrounding pixels.
107  */
108  static double CalcSigmaDepth(const Image<float> &ImgDepth,
109  const unsigned int x,
110  const unsigned int y,
111  const unsigned int HalfWinSize);
112 
113 
114  /** @brief This function denoises a PMD-Depth image by Median and
115  * variance filtering. Sets noise pixels to zero.
116  */
117  static int DenoiseDepthImage(Image<float> &ImgDepth,
118  int size=1,
119  double sigmaVarianz=0.5);
120 
121  /** @brief This function adds noise to a depth image.
122  * The intention is to add noise to a synthetically
123  * created depth image. The noise sigma is similar to
124  * that of a good conditioned PMD-measurement.
125  */
126  static int AddNoiseToDepthImage(Image<float> &ImgDepth);
127 
128 
129  /** @brief This function scales the depth image with the given
130  * scale factor.
131  */
132  static void ScaleDepthImage(Image<float> &ImgDepth, double scaleFactor);
133 
134  /** @brief Deletes (sets to 0) pixels in PMD-Image with a local
135  * variance > sigmaThresh. Eleminates depth noise.
136  * @author grest
137  */
138  static void DeleteHighVarianceValues(BIAS::Image<float> &img,
139  const double sigmaThresh,
140  const int halfwinSize=1);
141  /** @brief Markes pixels in PMD-Image with a local
142  * variance > sigmaThresh. Eleminates depth noise.
143  * @author grest
144  */
145  static void MarkHighVarianceValues(const BIAS::Image<float> &img,
146  BIAS::Image<float> &mark,
147  double sigmaThresh,
148  int halfwinSize=1);
149 
150  /**
151  * \brief Projects all points != 0 in image cIm to both other images cIm1 and cIm2
152  * and checks whether the 3D point projects to a valid point !=0 in the other images or if a valid
153  * point !=0 exists in the neighbourhood of size searchSize. If no valid points can be
154  * found in the other images in cImCheck the pixel in image cIm is invalidated (=0).
155  * \param cIm[in][out]: the image to check and invalidate.
156  * \param cImCheck[in]: the images to check against.
157  * \param cPCheck[in]: the projections to check against, same order as in cImCheck.
158  * \param searchSize[in]: the area around a projected pixel to search for neighbours (default = 3).
159  * \return number of deleted pixels, -1 on error
160  * \author ischiller
161  * \date 08/2010
162  */
163  static int CrossCheck(Image<float>& cIm, const Projection& cP,
164  std::vector<const Image<float>* >& cImCheck,
165  std::vector<const Projection*>& cPCheck,
166  int searchSize=3);
167 
168  protected:
169 
170  /** @brief These methods transform the depth image to fit the
171  * 2D-image. After transformation the Depth for every 2D-point
172  * is at the same pixel position in the depth image. There are
173  * 3 steps of transformaiton complexity: Only K, Only Rot+K, Free.
174  * @author Birger Streckel
175  */
176  static int FitDepthTo2DImageKOnly_(Image<float> &ImgToModify,
177  const PMDImageMetaData &MetaData2D,
178  PMDImageMetaData &MetaDataDepth);
179  static int FitDepthTo2DImageHomogr_(Image<float> &ImgToModify,
180  const PMDImageMetaData &MetaData2D,
181  PMDImageMetaData &MetaDataDepth);
182  static int FitDepthTo2DImageFree_(Image<float> &ImgToModify,
183  const Image<float> &ImgDepth,
184  const PMDImageMetaData &MetaData2D,
185  PMDImageMetaData &MetaDataDepth);
186 
187 
188  /** @brief Create a H-Matrix that converts the depth image to the 2D view
189  */
190  static HMatrix HFromMeta_(const PMDImageMetaData &MetaData2D,
191  const PMDImageMetaData &MetaDataDepth);
192  };
193 
194 
195 }
196 #endif
a 3x3 Matrix describing projective transformations between planes
Definition: HMatrix.hh:39
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
Store extrinsic and intrinsic camera parameters for Rotation is in axis * angle representation image ...
Definition: PMDImageIO.hh:70
this class collects all additional data chunks of type AppData to be written into/read from an image ...
Definition: MetaData.hh:121
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48