SMIL  1.0.4
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''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _D_MORPHO_RESIDUES_HPP
31 #define _D_MORPHO_RESIDUES_HPP
32 
33 #include "DMorphoBase.hpp"
34 
35 namespace smil
36 {
61  template <class T>
62  RES_T gradient(const Image<T> &imIn, Image<T> &imOut,
63  const StrElt &se = DEFAULT_SE)
64  {
65  return gradient(imIn, imOut, se, se);
66  }
67 
85  template <class T>
86  RES_T gradient(const Image<T> &imIn, Image<T> &imOut, const StrElt &dilSe,
87  const StrElt &eroSe)
88  {
89  Image<T> dilIm(imIn);
90  Image<T> eroIm(imIn);
91 
92  RES_T res = dilate(imIn, dilIm, dilSe);
93  if (res == RES_OK)
94  res = erode(imIn, eroIm, eroSe);
95  if (res == RES_OK)
96  res = sub(dilIm, eroIm, imOut);
97  return res;
98  }
99 
100 
114  template <class T>
115  RES_T topHat(const Image<T> &imIn, Image<T> &imOut,
116  const StrElt &se = DEFAULT_SE)
117  {
118  Image<T> openIm(imIn);
119 
120  RES_T res = open(imIn, openIm, se);
121  if (res == RES_OK)
122  res = sub(imIn, openIm, imOut);
123  return res;
124  }
125 
139  template <class T>
140  RES_T dualTopHat(const Image<T> &imIn, Image<T> &imOut,
141  const StrElt &se = DEFAULT_SE)
142  {
143  Image<T> closeIm(imIn);
144 
145  RES_T res = close(imIn, closeIm, se);
146  if (res == RES_OK)
147  res = sub(closeIm, imIn, imOut);
148  return res;
149  }
150 
153 } // namespace smil
154 
155 #endif // _D_MORPHO_RESIDUES_HPP
Main Image class.
Definition: DImage.hpp:57
Base structuring element.
Definition: DStructuringElement.h:68
RES_T sub(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
sub() - Subtraction between two images
Definition: DImageArith.hpp:160
RES_T open(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
open() - Morphological grayscale opening
Definition: DMorphoFilter.hpp:123
RES_T close(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
close() - Morphological grayscale closing
Definition: DMorphoFilter.hpp:70
RES_T erode(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE, const T borderVal=ImDtTypes< T >::max())
erode() - Morphological grayscale erosion
Definition: DMorphoBase.hpp:112
RES_T dilate(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE, const T borderVal=ImDtTypes< T >::min())
dilate() - Morphological grayscale dilation
Definition: DMorphoBase.hpp:65
RES_T dualTopHat(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
dualTopHat() - Dual Top-Hat
Definition: DMorphoResidues.hpp:140
RES_T topHat(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
topHat() - Top-Hat
Definition: DMorphoResidues.hpp:115
RES_T gradient(const Image< T > &imIn, Image< T > &imOut, const StrElt &dilSe, const StrElt &eroSe)
gradient() - Morphological gradient
Definition: DMorphoResidues.hpp:86