1 /*
2   Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization
3   dedicated to making software imaging solutions freely available.
4 
5   You may not use this file except in compliance with the License.  You may
6   obtain a copy of the License at
7 
8     https://imagemagick.org/script/license.php
9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 
16   MagickCore morphology methods.
17 */
18 #ifndef MAGICKCORE_MORPHOLOGY_H
19 #define MAGICKCORE_MORPHOLOGY_H
20 
21 #include "magick/geometry.h"
22 
23 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26 
27 typedef enum
28 {
29   UndefinedKernel,    /* equivalent to UnityKernel */
30   UnityKernel,        /* The no-op or 'original image' kernel */
31   GaussianKernel,     /* Convolution Kernels, Gaussian Based */
32   DoGKernel,
33   LoGKernel,
34   BlurKernel,
35   CometKernel,
36   LaplacianKernel,    /* Convolution Kernels, by Name */
37   SobelKernel,
38   FreiChenKernel,
39   RobertsKernel,
40   PrewittKernel,
41   CompassKernel,
42   KirschKernel,
43   DiamondKernel,      /* Shape Kernels */
44   SquareKernel,
45   RectangleKernel,
46   OctagonKernel,
47   DiskKernel,
48   PlusKernel,
49   CrossKernel,
50   RingKernel,
51   PeaksKernel,         /* Hit And Miss Kernels */
52   EdgesKernel,
53   CornersKernel,
54   DiagonalsKernel,
55   LineEndsKernel,
56   LineJunctionsKernel,
57   RidgesKernel,
58   ConvexHullKernel,
59   ThinSEKernel,
60   SkeletonKernel,
61   ChebyshevKernel,    /* Distance Measuring Kernels */
62   ManhattanKernel,
63   OctagonalKernel,
64   EuclideanKernel,
65   UserDefinedKernel,   /* User Specified Kernel Array */
66   BinomialKernel
67 } KernelInfoType;
68 
69 typedef enum
70 {
71   UndefinedMorphology,
72 /* Convolve / Correlate weighted sums */
73   ConvolveMorphology,           /* Weighted Sum with reflected kernel */
74   CorrelateMorphology,          /* Weighted Sum using a sliding window */
75 /* Low-level Morphology methods */
76   ErodeMorphology,              /* Minimum Value in Neighbourhood */
77   DilateMorphology,             /* Maximum Value in Neighbourhood */
78   ErodeIntensityMorphology,     /* Pixel Pick using GreyScale Erode */
79   DilateIntensityMorphology,    /* Pixel Pick using GreyScale Dialate */
80   DistanceMorphology,           /* Add Kernel Value, take Minimum */
81 /* Second-level Morphology methods */
82   OpenMorphology,               /* Dilate then Erode */
83   CloseMorphology,              /* Erode then Dilate */
84   OpenIntensityMorphology,      /* Pixel Pick using GreyScale Open */
85   CloseIntensityMorphology,     /* Pixel Pick using GreyScale Close */
86   SmoothMorphology,             /* Open then Close */
87 /* Difference Morphology methods */
88   EdgeInMorphology,             /* Dilate difference from Original */
89   EdgeOutMorphology,            /* Erode difference from Original */
90   EdgeMorphology,               /* Dilate difference with Erode */
91   TopHatMorphology,             /* Close difference from Original */
92   BottomHatMorphology,          /* Open difference from Original */
93 /* Recursive Morphology methods */
94   HitAndMissMorphology,         /* Foreground/Background pattern matching */
95   ThinningMorphology,           /* Remove matching pixels from image */
96   ThickenMorphology,            /* Add matching pixels from image */
97 /* Experimental Morphology methods */
98   VoronoiMorphology,            /* distance matte channel copy nearest color */
99   IterativeDistanceMorphology   /* Add Kernel Value, take Minimum */
100 } MorphologyMethod;
101 
102 typedef struct KernelInfo
103 {
104   KernelInfoType
105     type;
106 
107   size_t
108     width,
109     height;
110 
111   ssize_t
112     x,
113     y;
114 
115   double
116     *values,
117     minimum,
118     maximum,
119     negative_range,
120     positive_range,
121     angle;
122 
123   struct KernelInfo
124     *next;
125 
126   size_t
127     signature;
128 } KernelInfo;
129 
130 extern MagickExport KernelInfo
131   *AcquireKernelInfo(const char *),
132   *AcquireKernelBuiltIn(const KernelInfoType,const GeometryInfo *),
133   *CloneKernelInfo(const KernelInfo *),
134   *DestroyKernelInfo(KernelInfo *);
135 
136 extern MagickExport Image
137   *MorphologyImage(const Image *,const MorphologyMethod,const ssize_t,
138     const KernelInfo *,ExceptionInfo *),
139   *MorphologyImageChannel(const Image *,const ChannelType,
140     const MorphologyMethod,const ssize_t,const KernelInfo *,ExceptionInfo *);
141 
142 extern MagickExport void
143   ScaleGeometryKernelInfo(KernelInfo *,const char *),
144   ScaleKernelInfo(KernelInfo *,const double,const GeometryFlags),
145   ShowKernelInfo(const KernelInfo *),
146   UnityAddKernelInfo(KernelInfo *,const double);
147 
148 #if defined(__cplusplus) || defined(c_plusplus)
149 }
150 #endif
151 
152 #endif
153