GaussBackground.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 
27 // IVT
28 #include "Image/ByteImage.h"
29 #include "Math/FloatVector.h"
30 #include "Math/Math2d.h"
31 
32 // C
33 #include <math.h>
34 
35 // probability distribution of a pixel in HS-space
37 {
38  Vec2d vMean; // mean of the distribution
39  Mat2d mCovariance; // inverse covariance matrix of the distribution (Sigma^-1)
40 
41  bool bShifted; // true if H-scale has been shifted by 128
42  // to avoid overflow problems
43  float fSatWeight; // weighting for the use of S-dist only vs HS-dist
44 };
45 
46 // class for learning, representation and segmentation of a background using
47 // a normal distribution in HS-space
49 {
50 public:
51  CGaussBackground(const int nWidth, const int nHeight);
53 
54  void LearnBackgroundRGB(CByteImage** pRGBImages, const int nNumImages);
55  void LearnBackground(CByteImage** pHSVImages, const int nNumImages);
56 
57  void GetBinaryForegroundImageRGB(const CByteImage* pInputImageRGB,
58  CByteImage* pForegroundImage);
59 
60  void SegmentImageRGB(const CByteImage* pInputImageRGB, CByteImage* pProbabilityImage);
61  void SegmentImageRGB(const CByteImage* pInputImageRGB, float* pProbabilityImage);
62  void SegmentImage(const CByteImage* pInputImageRGB,
63  const CByteImage* pInputImageHSV,
64  CByteImage* pProbabilityImage);
65  void SegmentImage(const CByteImage* pInputImageRGB,
66  const CByteImage* pInputImageHSV,
67  float* pProbabilityImage);
68 
69  void BinarizeAndFillHoles(CByteImage* pProbabilityImage);
70 
71 private:
72  inline void FillHolesHorVert(const CByteImage* pInputImage,
73  CByteImage* pOutputImage,
74  const int nRadius = 20);
75  inline void
76  FillHolesDiag(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 20);
77  inline void FillHolesHorVertDiag(const CByteImage* pInputImage,
78  CByteImage* pOutputImage,
79  const int nRadius = 55);
80  inline double CalcProbOfPixel(const int nIndex, const Vec2d vHS_Value);
81 
82  CPixelProbabilityDistribution* m_pPixelProbabilityDistributions;
83  int m_nImageWidth, m_nImageHeight;
84 
85  CByteImage* m_pBackgroundRGB;
86 };
CGaussBackground::LearnBackgroundRGB
void LearnBackgroundRGB(CByteImage **pRGBImages, const int nNumImages)
Definition: GaussBackground.cpp:54
CPixelProbabilityDistribution::vMean
Vec2d vMean
Definition: GaussBackground.h:38
CGaussBackground::GetBinaryForegroundImageRGB
void GetBinaryForegroundImageRGB(const CByteImage *pInputImageRGB, CByteImage *pForegroundImage)
Definition: GaussBackground.cpp:544
CGaussBackground::CGaussBackground
CGaussBackground(const int nWidth, const int nHeight)
Definition: GaussBackground.cpp:32
CGaussBackground::SegmentImage
void SegmentImage(const CByteImage *pInputImageRGB, const CByteImage *pInputImageHSV, CByteImage *pProbabilityImage)
Definition: GaussBackground.cpp:583
CPixelProbabilityDistribution
Definition: GaussBackground.h:36
CGaussBackground::~CGaussBackground
~CGaussBackground()
Definition: GaussBackground.cpp:41
CGaussBackground
Definition: GaussBackground.h:48
CPixelProbabilityDistribution::fSatWeight
float fSatWeight
Definition: GaussBackground.h:43
CGaussBackground::SegmentImageRGB
void SegmentImageRGB(const CByteImage *pInputImageRGB, CByteImage *pProbabilityImage)
Definition: GaussBackground.cpp:553
CPixelProbabilityDistribution::bShifted
bool bShifted
Definition: GaussBackground.h:41
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:736
CGaussBackground::LearnBackground
void LearnBackground(CByteImage **pHSVImages, const int nNumImages)
Definition: GaussBackground.cpp:80
CPixelProbabilityDistribution::mCovariance
Mat2d mCovariance
Definition: GaussBackground.h:39
CGaussBackground::BinarizeAndFillHoles
void BinarizeAndFillHoles(CByteImage *pProbabilityImage)
Definition: GaussBackground.cpp:263