1 /** \file
2  * \brief Image Processing - Global Operations
3  *
4  * See Copyright Notice in im_lib.d
5  */
6 
7 module im.process_glo;
8 
9 import im.image;
10 
11 extern (C) @safe nothrow:
12 
13 
14 
15 /** \defgroup transform Other Domain Transform Operations
16  * \par
17  * Hough, Distance.
18  *
19  * See \ref im_process_glo.h
20  * \ingroup process */
21 
22 /** Hough Lines Transform. \n
23  * It will detect white lines in a black background. So the source image must be a IM_BINARY image
24  * with the white lines of interest enhanced. The better the threshold with the white lines the better
25  * the line detection. \n
26  * The target image must have IM_GRAY, IM_INT, hg_width=180, hg_height=2*rmax+1,
27  * where rmax is the image diagonal/2 (rmax = srqrt(width*width + height*height)). \n
28  * The hough transform defines  "cos(theta) * X  + sin(theta) * Y = rho" and the parameters are in the interval: \n
29  * theta = "0 .. 179", rho = "-hg_height/2 .. hg_height/2" .\n
30  * Where rho is the perpendicular distance from the center of the image and theta the angle with the normal.
31  * So do not confuse theta with the line angle, they are perpendicular. \n
32  * Returns zero if the counter aborted. \n
33  * Inspired from ideas in XITE, Copyright 1991, Blab, UiO \n
34  * http://www.ifi.uio.no/~blab/Software/Xite/  \n
35  * Not using OpenMP when enabled.
36  *
37  * \verbatim im.ProcessHoughLines(src_image: imImage, dst_image: imImage) -> counter: boolean [in Lua 5] \endverbatim
38  * \verbatim im.ProcessHoughLinesNew(image: imImage) -> counter: boolean, new_image: imImage [in Lua 5] \endverbatim
39  * \ingroup transform */
40 int imProcessHoughLines(const(imImage) * src_image, imImage* dst_image);
41 
42 /** Draw detected hough lines. \n
43  * The source and target images can be IM_MAP, IM_GRAY or IM_RGB, with data type IM_BYTE. \n
44  * Can be done in-place. \n
45  * If the hough transform is not NULL, then the hough points are filtered to include only lines
46  * that are significally different from each other. \n
47  * The hough image is the hough transform image, but it is optional and can be NULL.
48  * If not NULL then it will be used to filter lines that are very similar. \n
49  * The hough points image is a hough transform image that was thresholded to a IM_BINARY image,
50  * usually using a Local Max threshold operation (see \ref imProcessLocalMaxThreshold). Again the better the threshold the better the results. \n
51  * The detected lines will be drawn using a red color.
52  * If the target image is IM_GRAY, it will be changed to IM_MAP. \n
53  * If the target image is IM_RGB, then only the red plane will be changed.
54  * Returns the number of detected lines. \n
55  * Not using OpenMP when enabled.
56  *
57  * \verbatim im.ProcessHoughLinesDraw(src_image: imImage, hough: imImage, hough_points: imImage, dst_image: imImage) -> lines: number [in Lua 5] \endverbatim
58  * \verbatim im.ProcessHoughLinesDrawNew(image: imImage, hough: imImage, hough_points: imImage) -> lines: number, new_image: imImage [in Lua 5] \endverbatim
59  * \ingroup transform */
60 int imProcessHoughLinesDraw(const(imImage) * src_image, const(imImage) * hough, const(imImage) * hough_points, imImage* dst_image);
61 
62 /** Calculates the Cross Correlation in the frequency domain. \n
63  * CrossCorr(a,b) = IFFT(Conj(FFT(a))*FFT(b)) \n
64  * Images must be of the same size and only target image must be of type complex.
65  *
66  * \verbatim im.ProcessCrossCorrelation(src_image1: imImage, src_image2: imImage, dst_image: imImage) [in Lua 5] \endverbatim
67  * \verbatim im.ProcessCrossCorrelationNew(image1: imImage, image2: imImage) -> new_image: imImage [in Lua 5] \endverbatim
68  * \ingroup transform */
69 void imProcessCrossCorrelation(const(imImage) * src_image1, const(imImage) * src_image2, imImage* dst_image);
70 
71 /** Calculates the Auto Correlation in the frequency domain. \n
72  * Uses the cross correlation.
73  * Images must be of the same size and only target image must be of type complex.
74  *
75  * \verbatim im.ProcessAutoCorrelation(src_image: imImage, dst_image: imImage) [in Lua 5] \endverbatim
76  * \verbatim im.ProcessAutoCorrelationNew(image: imImage) -> new_image: imImage [in Lua 5] \endverbatim
77  * \ingroup transform */
78 void imProcessAutoCorrelation(const(imImage) * src_image, imImage* dst_image);
79 
80 /** Calculates the Distance Transform of a binary image
81  * using an aproximation of the euclidian distance.\n
82  * Each white pixel in the binary image is
83  * assigned a value equal to its distance from the nearest
84  * black pixel. \n
85  * Uses a two-pass algorithm incrementally calculating the distance. \n
86  * Source image must be IM_BINARY, target must be IM_FLOAT.
87  *
88  * \verbatim im.ProcessDistanceTransform(src_image: imImage, dst_image: imImage) [in Lua 5] \endverbatim
89  * \verbatim im.ProcessDistanceTransformNew(image: imImage) -> new_image: imImage [in Lua 5] \endverbatim
90  * \ingroup transform */
91 void imProcessDistanceTransform(const(imImage) * src_image, imImage* dst_image);
92 
93 /** Marks all the regional maximum of the distance transform. \n
94  * source is IMGRAY/IM_FLOAT target in IM_BINARY. \n
95  * We consider maximum all connected pixel values that have smaller pixel values around it.
96  *
97  * \verbatim im.ProcessRegionalMaximum(src_image: imImage, dst_image: imImage) [in Lua 5] \endverbatim
98  * \verbatim im.ProcessRegionalMaximumNew(image: imImage) -> new_image: imImage [in Lua 5] \endverbatim
99  * \ingroup transform */
100 void imProcessRegionalMaximum(const(imImage) * src_image, imImage* dst_image);
101 
102 
103 
104 /** \defgroup fourier Fourier Transform Operations
105  * \par
106  * All Fourier transforms use FFTW library. \n
107  * The pre-compiled binaries for FFTW version 2.1.5 includes all the necessary files.
108  * The pre-compiled binaries for FFTW version 3.x depends on an external library, not provided.
109  * To build the code that uses FFTW version 3 you must define USE_FFTW3.
110  * \par
111  * FFTW Copyright Matteo Frigo, Steven G. Johnson and the MIT. \n
112  * http://www.fftw.org                                         \n
113  * See "fftw.h"
114  * \par
115  * Must link with "im_fftw" library. \n
116  * \par
117  * IMPORTANT: The FFTW lib has a GPL license. The license of the "im_fftw" library is automatically the GPL.
118  * So you cannot use it for commercial applications without contacting the authors.
119  * \par
120  * FFTW 2.x can have float or double functions, not both. \n
121  * FFTW 3.x can have both, but we use only one to keep the
122  * code compatible with version 2. \n
123  * So by default the pre-compiled binaries are built with "float" support only.
124  * \par
125  * See \ref im_process_glo.h
126  * \ingroup process */
127 
128 /** Forward FFT. \n
129  * The result has its lowest frequency at the center of the image. \n
130  * This is an unnormalized fft. \n
131  * Images must be of the same size. Target image must be of type float complex.
132  *
133  * \verbatim im.ProcessFFT(src_image: imImage, dst_image: imImage) [in Lua 5] \endverbatim
134  * \verbatim im.ProcessFFTNew(image: imImage) -> new_image: imImage [in Lua 5] \endverbatim
135  * \ingroup fourier */
136 void imProcessFFT(const(imImage) * src_image, imImage* dst_image);
137 
138 /** Inverse FFT. \n
139  * The image has its lowest frequency restored to the origin before the transform. \n
140  * The result is normalized by (width*height). \n
141  * Images must be of the same size and both must be of type float complex.
142  *
143  * \verbatim im.ProcessIFFT(src_image: imImage, dst_image: imImage) [in Lua 5] \endverbatim
144  * \verbatim im.ProcessIFFTNew(image: imImage) -> new_image: imImage [in Lua 5] \endverbatim
145  * \ingroup fourier */
146 void imProcessIFFT(const(imImage) * src_image, imImage* dst_image);
147 
148 /** Raw in-place FFT (forward or inverse). \n
149  * The lowest frequency can be centered after forward, or
150  * can be restored to the origin before inverse. \n
151  * The result can be normalized after the transform by sqrt(w*h) [1] or by (w*h) [2],
152  * or left unnormalized [0]. \n
153  * Images must be of the same size and both must be of type float complex.
154  *
155  * \verbatim im.ProcessFFTraw(image: imImage, inverse: number, center: number, normalize: number) [in Lua 5] \endverbatim
156  * \ingroup fourier */
157 void imProcessFFTraw(imImage* image, int inverse, int center, int normalize);
158 
159 /** Auxiliary function for the raw FFT. \n
160  * This is the function used internally to change the lowest frequency position in the image. \n
161  * If the image size has even dimensions the flag "center2origin" is useless. But if it is odd,
162  * you must specify if its from center to origin (usually used before inverse) or
163  * from origin to center (usually used after forward). \n
164  * Notice that this function is used for images in the the frequency domain. \n
165  * Image type must be float complex.
166  *
167  * \verbatim im.ProcessSwapQuadrants(image: imImage, center2origin: number) [in Lua 5] \endverbatim
168  * \ingroup fourier */
169 void imProcessSwapQuadrants(imImage* image, int center2origin);
170 
171 
172 
173 /** \defgroup openmp OpenMP Utilities
174  * \par
175  * Used inside im_process_omp only. But also exported to Lua.
176  * These functions do not use OpenMP,
177  * they are used when OpenMP is enabled in im_process.
178  * See \ref im_util.h
179  * \ingroup process */
180 
181 /** Sets the minimum number of iterations to split into threads. \n
182  * Default value is 250000, or an image with 500x500. \n
183  * Returns the previous value.
184  *
185  * \verbatim im.ProcessOpenMPSetMinCount(min_count: number) -> old_min_count: number [in Lua 5] \endverbatim
186  * \ingroup openmp */
187 int imProcessOpenMPSetMinCount(int min_count);
188 
189 /** Sets the number of threads. \n
190  * Does nothing if OpenMP is not enabled. \n
191  * Returns the previous value.
192  *
193  * \verbatim im.ProcessOpenMPSetNumThreads(min_count: number) -> old_min_count: number [in Lua 5] \endverbatim
194  * \ingroup openmp */
195 int imProcessOpenMPSetNumThreads(int count);