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