SMIL  0.9.1
DMorphoResidues.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_RESIDUES_HPP
31 #define _D_MORPHO_RESIDUES_HPP
32 
33 #include "DMorphoBase.hpp"
34 
35 
36 namespace smil
37 {
48  template <class T>
49  RES_T gradient(const Image<T> &imIn, Image<T> &imOut, const StrElt &dilSe, const StrElt &eroSe)
50  {
51  Image<T> dilIm(imIn);
52  Image<T> eroIm(imIn);
53 
54  RES_T res = dilate(imIn, dilIm, dilSe);
55  if (res==RES_OK)
56  res = erode(imIn, eroIm, eroSe);
57  if (res==RES_OK)
58  res = sub(dilIm, eroIm, imOut);
59  return res;
60  }
61 
62  template <class T>
63  RES_T gradient(const Image<T> &imIn, Image<T> &imOut, const StrElt &se=DEFAULT_SE)
64  {
65  return gradient(imIn, imOut, se, se);
66  }
67 
68 
73  template <class T>
74  RES_T topHat(const Image<T> &imIn, Image<T> &imOut, const StrElt &se=DEFAULT_SE)
75  {
76  Image<T> openIm(imIn);
77 
78  RES_T res = open(imIn, openIm, se);
79  if (res==RES_OK)
80  res = sub(imIn, openIm, imOut);
81  return res;
82  }
83 
88  template <class T>
89  RES_T dualTopHat(const Image<T> &imIn, Image<T> &imOut, const StrElt &se=DEFAULT_SE)
90  {
91  Image<T> closeIm(imIn);
92 
93  RES_T res = close(imIn, closeIm, se);
94  if (res==RES_OK)
95  res = sub(closeIm, imIn, imOut);
96  return res;
97  }
98 
101 } //namespace smil
102 
103 
104 
105 #endif // _D_MORPHO_RESIDUES_HPP
106 
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
RES_T sub(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Subtraction.
Definition: DImageArith.hpp:446
RES_T close(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
Morphological grayscale closing.
Definition: DMorphoBase.hpp:127
RES_T dualTopHat(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
Close (dual) Top-Hat.
Definition: DMorphoResidues.hpp:89
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
RES_T open(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
Morphological grayscale opening.
Definition: DMorphoBase.hpp:159
RES_T gradient(const Image< T > &imIn, Image< T > &imOut, const StrElt &dilSe, const StrElt &eroSe)
Morphological gradient.
Definition: DMorphoResidues.hpp:49
RES_T topHat(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
Open Top-Hat.
Definition: DMorphoResidues.hpp:74