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/Math2d.h"
30 #include "Math/FloatVector.h"
31 
32 // C
33 #include <math.h>
34 
35 
36 
37 // probability distribution of a pixel in HS-space
39 {
40  Vec2d vMean; // mean of the distribution
41  Mat2d mCovariance; // inverse covariance matrix of the distribution (Sigma^-1)
42 
43  bool bShifted; // true if H-scale has been shifted by 128
44  // to avoid overflow problems
45  float fSatWeight; // weighting for the use of S-dist only vs HS-dist
46 };
47 
48 
49 // class for learning, representation and segmentation of a background using
50 // a normal distribution in HS-space
52 {
53 public:
54 
55  CGaussBackground(const int nWidth, const int nHeight);
57 
58  void LearnBackgroundRGB(CByteImage** pRGBImages, const int nNumImages);
59  void LearnBackground(CByteImage** pHSVImages, const int nNumImages);
60 
61  void GetBinaryForegroundImageRGB(const CByteImage* pInputImageRGB, CByteImage* pForegroundImage);
62 
63  void SegmentImageRGB(const CByteImage* pInputImageRGB, CByteImage* pProbabilityImage);
64  void SegmentImageRGB(const CByteImage* pInputImageRGB, float* pProbabilityImage);
65  void SegmentImage(const CByteImage* pInputImageRGB, const CByteImage* pInputImageHSV, CByteImage* pProbabilityImage);
66  void SegmentImage(const CByteImage* pInputImageRGB, const CByteImage* pInputImageHSV, float* pProbabilityImage);
67 
68  void BinarizeAndFillHoles(CByteImage* pProbabilityImage);
69 
70 private:
71 
72  inline void FillHolesHorVert(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 20);
73  inline void FillHolesDiag(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 20);
74  inline void FillHolesHorVertDiag(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 55);
75  inline double CalcProbOfPixel(const int nIndex, const Vec2d vHS_Value);
76 
77  CPixelProbabilityDistribution* m_pPixelProbabilityDistributions;
78  int m_nImageWidth, m_nImageHeight;
79 
80  CByteImage* m_pBackgroundRGB;
81 };
82 
83 
CGaussBackground::LearnBackgroundRGB
void LearnBackgroundRGB(CByteImage **pRGBImages, const int nNumImages)
Definition: GaussBackground.cpp:63
CPixelProbabilityDistribution::vMean
Vec2d vMean
Definition: GaussBackground.h:40
CGaussBackground::GetBinaryForegroundImageRGB
void GetBinaryForegroundImageRGB(const CByteImage *pInputImageRGB, CByteImage *pForegroundImage)
Definition: GaussBackground.cpp:536
CGaussBackground::CGaussBackground
CGaussBackground(const int nWidth, const int nHeight)
Definition: GaussBackground.cpp:37
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:694
CGaussBackground::SegmentImage
void SegmentImage(const CByteImage *pInputImageRGB, const CByteImage *pInputImageHSV, CByteImage *pProbabilityImage)
Definition: GaussBackground.cpp:577
CPixelProbabilityDistribution
Definition: GaussBackground.h:38
CGaussBackground::~CGaussBackground
~CGaussBackground()
Definition: GaussBackground.cpp:48
CGaussBackground
Definition: GaussBackground.h:51
CPixelProbabilityDistribution::fSatWeight
float fSatWeight
Definition: GaussBackground.h:45
CGaussBackground::SegmentImageRGB
void SegmentImageRGB(const CByteImage *pInputImageRGB, CByteImage *pProbabilityImage)
Definition: GaussBackground.cpp:545
CPixelProbabilityDistribution::bShifted
bool bShifted
Definition: GaussBackground.h:43
CGaussBackground::LearnBackground
void LearnBackground(CByteImage **pHSVImages, const int nNumImages)
Definition: GaussBackground.cpp:90
CPixelProbabilityDistribution::mCovariance
Mat2d mCovariance
Definition: GaussBackground.h:41
CGaussBackground::BinarizeAndFillHoles
void BinarizeAndFillHoles(CByteImage *pProbabilityImage)
Definition: GaussBackground.cpp:265