SMIL  0.9.1
DMorphoMeasures.hpp
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _D_MORPHO_MEASURES_HPP
31 #define _D_MORPHO_MEASURES_HPP
32 
33 #include "Core/include/DImage.h"
34 #include "DMorphoBase.hpp"
35 
36 
37 namespace smil
38 {
53  template <class T>
54  vector<double> measGranulometry(const Image<T> &imIn, const StrElt &se=DEFAULT_SE, const unsigned int stepSize=1, bool CDF=true)
55  {
56  vector<double> res;
57 
58  ASSERT(imIn.isAllocated(), res);
59 
60  Image<T> imEro(imIn, true); // clone
61  Image<T> imOpen(imIn);
62 
63  size_t seSize = stepSize;
64  double a0 = area(imIn), a1;
65 
66  do
67  {
68  erode(imEro, imEro, se(stepSize));
69  dilate(imEro, imOpen, se(seSize));
70  a1 = area(imOpen);
71  res.push_back(a0-a1);
72  a0 = a1;
73  seSize += stepSize;
74 
75  } while(a0>0);
76 
77  if (CDF)
78  {
79  double aSum = 0;
80  for (size_t i=0;i<res.size();i++)
81  aSum += res[i];
82  res[0] /= aSum;
83  for (size_t i=1;i<res.size();i++)
84  res[i] = res[i]/aSum + res[i-1];
85  }
86 
87  return res;
88  }
89 
90 
93 } // namespace smil
94 
95 
96 
97 #endif // _D_MORPHO_MEASURES_HPP
98 
RES_T dilate(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE, T borderVal=ImDtTypes< T >::min())
Morphological grayscale dilation.
Definition: DMorphoBase.hpp:65
Definition: DColorConvert.h:38
bool isAllocated() const
Check if the image is allocated.
Definition: DBaseImage.h:163
size_t area(const Image< T > &imIn)
Area of an image.
Definition: DMeasures.hpp:70
Base structuring element.
Definition: DStructuringElement.h:51
Main Image class.
Definition: DQVtkViewer.hpp:44
RES_T erode(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE, T borderVal=ImDtTypes< T >::max())
Morphological grayscale erosion.
Definition: DMorphoBase.hpp:101
vector< double > measGranulometry(const Image< T > &imIn, const StrElt &se=DEFAULT_SE, const unsigned int stepSize=1, bool CDF=true)
Granulometry by openings.
Definition: DMorphoMeasures.hpp:54