IM: im_process_loc.h Source File
From IM - Imaging Libray
im_process_loc.h
Go to the documentation of this file.00001 /** \file 00002 * \brief Image Processing - Local Operations 00003 * 00004 * See Copyright Notice in im_lib.h 00005 * $Id: Exp $ 00006 */ 00007 00008 #ifndef __IM_PROCESS_LOC_H 00009 #define __IM_PROCESS_LOC_H 00010 00011 #include "im_image.h" 00012 00013 #if defined(__cplusplus) 00014 extern "C" { 00015 #endif 00016 00017 00018 00019 /** \defgroup resize Image Resize 00020 * \par 00021 * Operations to change the image size. 00022 * \par 00023 * See \ref im_process_loc.h 00024 * \ingroup process */ 00025 00026 /** Only reduze the image size using the given decimation order. \n 00027 * Supported interpolation orders: 00028 * \li 0 - zero order (mean) 00029 * \li 1 - first order (bilinear decimation) 00030 * Images must be of the same type. \n 00031 * Returns zero if the counter aborted. 00032 * \ingroup resize */ 00033 int imProcessReduce(const imImage* src_image, imImage* dst_image, int order); 00034 00035 /** Change the image size using the given interpolation order. \n 00036 * Supported interpolation orders: 00037 * \li 0 - zero order (near neighborhood) 00038 * \li 1 - first order (bilinear interpolation) 00039 * \li 3 - third order (bicubic interpolation) 00040 * Images must be of the same type. \n 00041 * Returns zero if the counter aborted. 00042 * \ingroup resize */ 00043 int imProcessResize(const imImage* src_image, imImage* dst_image, int order); 00044 00045 /** Reduze the image area by 4 (w/2,h/2). \n 00046 * Images must be of the same type. Destiny image size must be source image width/2, height/2. 00047 * \ingroup resize */ 00048 void imProcessReduceBy4(const imImage* src_image, imImage* dst_image); 00049 00050 /** Reduze the image size by removing pixels. \n 00051 * Images must be of the same type. Destiny image size must be smaller than source image width-xmin, height-ymin. 00052 * \ingroup resize */ 00053 void imProcessCrop(const imImage* src_image, imImage* dst_image, int xmin, int ymin); 00054 00055 /** Increase the image size by adding pixels with zero value. \n 00056 * Images must be of the same type. Destiny image size must be greatter than source image width+xmin, height+ymin. 00057 * \ingroup resize */ 00058 void imProcessAddMargins(const imImage* src_image, imImage* dst_image, int xmin, int ymin); 00059 00060 00061 00062 /** \defgroup geom Geometric Operations 00063 * \par 00064 * Operations to change the shape of the image. 00065 * \par 00066 * See \ref im_process_loc.h 00067 * \ingroup process */ 00068 00069 /** Calculates the size of the new image after rotation. 00070 * \ingroup geom */ 00071 void imProcessCalcRotateSize(int width, int height, int *new_width, int *new_height, double cos0, double sin0); 00072 00073 /** Rotates the image using the given interpolation order (see imProcessResize). \n 00074 * Images must be of the same type. The destiny size can be calculated using \ref imProcessCalcRotateSize. \n 00075 * Returns zero if the counter aborted. 00076 * \ingroup geom */ 00077 int imProcessRotate(const imImage* src_image, imImage* dst_image, double cos0, double sin0, int order); 00078 00079 /** Rotate the image in 90 degrees counterclockwise or clockwise. Swap columns by lines. \n 00080 * Images must be of the same type. Destiny width and height must be source height and width. 00081 * \ingroup geom */ 00082 void imProcessRotate90(const imImage* src_image, imImage* dst_image, int dir); 00083 00084 /** Rotate the image in 180 degrees. Swap columns and swap lines. \n 00085 * Images must be of the same type and size. 00086 * \ingroup geom */ 00087 void imProcessRotate180(const imImage* src_image, imImage* dst_image); 00088 00089 /** Mirrors the image in a horizontal flip. Swap columns. \n 00090 * Images must be of the same type and size. 00091 * \ingroup geom */ 00092 void imProcessMirror(const imImage* src_image, imImage* dst_image); 00093 00094 /** Apply a vertical flip. Swap lines. \n 00095 * Images must be of the same type and size. 00096 * \ingroup geom */ 00097 void imProcessFlip(const imImage* src_image, imImage* dst_image); 00098 00099 /** Apply a radial distortion using the given interpolation order (see imProcessResize). \n 00100 * Images must be of the same type and size. Returns zero if the counter aborted. 00101 * \ingroup geom */ 00102 int imProcessRadial(const imImage* src_image, imImage* dst_image, float k1, int order); 00103 00104 00105 00106 /** \defgroup morphgray Morphology Operations for Gray Images 00107 * \par 00108 * See \ref im_process_loc.h 00109 * \ingroup process */ 00110 00111 /** Base gray morphology convolution. \n 00112 * Supports all data types except IM_COMPLEX. Can be applied on color images. \n 00113 * Kernel is always IM_INT. Use kernel size odd for better results. \n 00114 * You can use the maximum value or else the minimum value. \n 00115 * No border extensions are used. 00116 * All the gray morphology operations use this function. \n 00117 * If the kernel image attribute "Description" exists it is used by the counter. 00118 * \ingroup morphgray */ 00119 int imProcessGrayMorphConvolve(const imImage* src_image, imImage* dst_image, const imImage* kernel, int ismax); 00120 00121 /** Gray morphology convolution with a kernel full of "0"s and use minimum value. 00122 * \ingroup morphgray */ 00123 int imProcessGrayMorphErode(const imImage* src_image, imImage* dst_image, int kernel_size); 00124 00125 /** Gray morphology convolution with a kernel full of "0"s and use maximum value. 00126 * \ingroup morphgray */ 00127 int imProcessGrayMorphDilate(const imImage* src_image, imImage* dst_image, int kernel_size); 00128 00129 /** Erode+Dilate. 00130 * \ingroup morphgray */ 00131 int imProcessGrayMorphOpen(const imImage* src_image, imImage* dst_image, int kernel_size); 00132 00133 /** Dilate+Erode. 00134 * \ingroup morphgray */ 00135 int imProcessGrayMorphClose(const imImage* src_image, imImage* dst_image, int kernel_size); 00136 00137 /** Open+Difference. 00138 * \ingroup morphgray */ 00139 int imProcessGrayMorphTopHat(const imImage* src_image, imImage* dst_image, int kernel_size); 00140 00141 /** Close+Difference. 00142 * \ingroup morphgray */ 00143 int imProcessGrayMorphWell(const imImage* src_image, imImage* dst_image, int kernel_size); 00144 00145 /** Difference(Erode, Dilate). 00146 * \ingroup morphgray */ 00147 int imProcessGrayMorphGradient(const imImage* src_image, imImage* dst_image, int kernel_size); 00148 00149 00150 00151 /** \defgroup morphbin Morphology Operations for Binary Images 00152 * \par 00153 * See \ref im_process_loc.h 00154 * \ingroup process */ 00155 00156 /** Base binary morphology convolution. \n 00157 * Images are all IM_BINARY. Kernel is IM_INT. Use kernel size odd for better results. \n 00158 * Hit white means hit=1 and miss=0, or else hit=0 and miss=1. \n 00159 * Use -1 for don't care positions in kernel. \n 00160 * The operation can be repeated by a number of iterations. 00161 * The border is zero extended. \n 00162 * Almost all the binary morphology operations use this function.\n 00163 * If the kernel image attribute "Description" exists it is used by the counter. 00164 * \ingroup morphbin */ 00165 int imProcessBinMorphConvolve(const imImage* src_image, imImage* dst_image, const imImage* kernel, int hit_white, int iter); 00166 00167 /** Binary morphology convolution with a kernel full of "1"s and hit white. 00168 * \ingroup morphbin */ 00169 int imProcessBinMorphErode(const imImage* src_image, imImage* dst_image, int kernel_size, int iter); 00170 00171 /** Binary morphology convolution with a kernel full of "0"s and hit black. 00172 * \ingroup morphbin */ 00173 int imProcessBinMorphDilate(const imImage* src_image, imImage* dst_image, int kernel_size, int iter); 00174 00175 /** Erode+Dilate. 00176 * When iteration is more than one it means Erode+Erode+Erode+...+Dilate+Dilate+Dilate+... 00177 * \ingroup morphbin */ 00178 int imProcessBinMorphOpen(const imImage* src_image, imImage* dst_image, int kernel_size, int iter); 00179 00180 /** Dilate+Erode. 00181 * \ingroup morphbin */ 00182 int imProcessBinMorphClose(const imImage* src_image, imImage* dst_image, int kernel_size, int iter); 00183 00184 /** Erode+Difference. \n 00185 * The difference from the source image is applied only once. 00186 * \ingroup morphbin */ 00187 int imProcessBinMorphOutline(const imImage* src_image, imImage* dst_image, int kernel_size, int iter); 00188 00189 /** Thins the supplied binary image using Rosenfeld's parallel thinning algorithm. \n 00190 * Reference: \n 00191 * "Efficient Binary Image Thinning using Neighborhood Maps" \n 00192 * by Joseph M. Cychosz, 3ksnn64@ecn.purdue.edu \n 00193 * in "Graphics Gems IV", Academic Press, 1994 00194 * \ingroup morphbin */ 00195 void imProcessBinMorphThin(const imImage* src_image, imImage* dst_image); 00196 00197 00198 00199 /** \defgroup rank Rank Convolution Operations 00200 * \par 00201 * All the rank convolution use the same base function. Near the border the base function 00202 * includes only the real image pixels in the rank. No border extensions are used. 00203 * \par 00204 * See \ref im_process_loc.h 00205 * \ingroup process */ 00206 00207 /** Rank convolution using the median value. \n 00208 * Returns zero if the counter aborted. \n 00209 * Supports all data types except IM_COMPLEX. Can be applied on color images. 00210 * \ingroup rank */ 00211 int imProcessMedianConvolve(const imImage* src_image, imImage* dst_image, int kernel_size); 00212 00213 /** Rank convolution using (maximum-minimum) value. \n 00214 * Returns zero if the counter aborted. \n 00215 * Supports all data types except IM_COMPLEX. Can be applied on color images. 00216 * \ingroup rank */ 00217 int imProcessRangeConvolve(const imImage* src_image, imImage* dst_image, int kernel_size); 00218 00219 /** Rank convolution using the closest maximum or minimum value. \n 00220 * Returns zero if the counter aborted. \n 00221 * Supports all data types except IM_COMPLEX. Can be applied on color images. 00222 * \ingroup rank */ 00223 int imProcessRankClosestConvolve(const imImage* src_image, imImage* dst_image, int kernel_size); 00224 00225 /** Rank convolution using the maximum value. \n 00226 * Returns zero if the counter aborted. \n 00227 * Supports all data types except IM_COMPLEX. Can be applied on color images. 00228 * \ingroup rank */ 00229 int imProcessRankMaxConvolve(const imImage* src_image, imImage* dst_image, int kernel_size); 00230 00231 /** Rank convolution using the minimum value. \n 00232 * Returns zero if the counter aborted. \n 00233 * Supports all data types except IM_COMPLEX. Can be applied on color images. 00234 * \ingroup rank */ 00235 int imProcessRankMinConvolve(const imImage* src_image, imImage* dst_image, int kernel_size); 00236 00237 /** Threshold using a rank convolution with a range contrast function. \n 00238 * Supports all integer IM_GRAY images as source, and IM_BINARY as destiny. \n 00239 * Local variable threshold by the method of Bernsen. \n 00240 * Extracted from XITE, Copyright 1991, Blab, UiO \n 00241 * http://www.ifi.uio.no/~blab/Software/Xite/ 00242 \verbatim 00243 Reference: 00244 Bernsen, J: "Dynamic thresholding of grey-level images" 00245 Proc. of the 8th ICPR, Paris, Oct 1986, 1251-1255. 00246 Author: Oivind Due Trier 00247 \endverbatim 00248 * Returns zero if the counter aborted. 00249 * \ingroup threshold */ 00250 int imProcessRangeContrastThreshold(const imImage* src_image, imImage* dst_image, int kernel_size, int min_range); 00251 00252 /** Threshold using a rank convolution with a local max function. \n 00253 * Returns zero if the counter aborted. \n 00254 * Supports all integer IM_GRAY images as source, and IM_BINARY as destiny. 00255 * \ingroup threshold */ 00256 int imProcessLocalMaxThreshold(const imImage* src_image, imImage* dst_image, int kernel_size, int min_thres); 00257 00258 00259 00260 /** \defgroup convolve Convolution Operations 00261 * \par 00262 * See \ref im_process_loc.h 00263 * \ingroup process */ 00264 00265 /** Base Convolution with a kernel. \n 00266 * Kernel can be IM_INT or IM_FLOAT, but always IM_GRAY. Use kernel size odd for better results. \n 00267 * Supports all data types. The border is mirrored. \n 00268 * Returns zero if the counter aborted. Most of the convolutions use this function.\n 00269 * If the kernel image attribute "Description" exists it is used by the counter. 00270 * \ingroup convolve */ 00271 int imProcessConvolve(const imImage* src_image, imImage* dst_image, const imImage* kernel); 00272 00273 /** Repeats the convolution a number of times. \n 00274 * Returns zero if the counter aborted.\n 00275 * If the kernel image attribute "Description" exists it is used by the counter. 00276 * \ingroup convolve */ 00277 int imProcessConvolveRep(const imImage* src_image, imImage* dst_image, const imImage* kernel, int count); 00278 00279 /** Convolve with a kernel rotating it 8 times and getting the absolute maximum value. \n 00280 * Kernel must be square. \n 00281 * The rotation is implemented only for kernel sizes 3x3, 5x5 and 7x7. \n 00282 * Supports all data types except IM_COMPLEX. 00283 * Returns zero if the counter aborted.\n 00284 * If the kernel image attribute "Description" exists it is used by the counter. 00285 * \ingroup convolve */ 00286 int imProcessCompassConvolve(const imImage* src_image, imImage* dst_image, imImage* kernel); 00287 00288 /** Utility function to rotate a kernel one time. 00289 * \ingroup convolve */ 00290 void imProcessRotateKernel(imImage* kernel); 00291 00292 /** Difference(Gaussian1, Gaussian2). \n 00293 * Supports all data types, 00294 * but if source is IM_BYTE or IM_USHORT destiny image must be of type IM_INT. 00295 * \ingroup convolve */ 00296 int imProcessDiffOfGaussianConvolve(const imImage* src_image, imImage* dst_image, float stddev1, float stddev2); 00297 00298 /** Difference(Gaussian1, Gaussian2) using gaussian repetitions. \n 00299 * Supports all data types, 00300 * but if source is IM_BYTE or IM_USHORT destiny image must be of type IM_INT. 00301 * \ingroup convolve */ 00302 int imProcessDiffOfGaussianConvolveRep(const imImage* src_image, imImage* dst_image, float stddev1, float stddev2); 00303 00304 /** Convolution with a laplacian of a gaussian kernel. \n 00305 * Supports all data types, 00306 * but if source is IM_BYTE or IM_USHORT destiny image must be of type IM_INT. 00307 * \ingroup convolve */ 00308 int imProcessLapOfGaussianConvolve(const imImage* src_image, imImage* dst_image, float stddev); 00309 00310 /** Convolution with a kernel full of "1"s inside a circle. \n 00311 * Supports all data types. 00312 * \ingroup convolve */ 00313 int imProcessMeanConvolve(const imImage* src_image, imImage* dst_image, int kernel_size); 00314 00315 /** Convolution with a gaussian kernel. The gaussian in obtained by repetition of a base 3x3 IM_INT kernel. \n 00316 * Supports all data types. 00317 * \ingroup convolve */ 00318 int imProcessGaussianConvolveRep(const imImage* src_image, imImage* dst_image, float stddev); 00319 00320 /** Convolution with a float gaussian kernel. \n 00321 * Supports all data types. 00322 * \ingroup convolve */ 00323 int imProcessGaussianConvolve(const imImage* src_image, imImage* dst_image, float stddev); 00324 00325 /** Magnitude of the sobel convolution. \n 00326 * Supports all data types except IM_COMPLEX. 00327 * \ingroup convolve */ 00328 int imProcessSobelConvolve(const imImage* src_image, imImage* dst_image); 00329 00330 /** Finds the zero crossings of IM_INT and IM_FLOAT images. Crossings are marked with non zero values 00331 * indicating the intensity of the edge. It is usually used after a second derivative, laplace. \n 00332 * Extracted from XITE, Copyright 1991, Blab, UiO \n 00333 * http://www.ifi.uio.no/~blab/Software/Xite/ 00334 * \ingroup convolve */ 00335 void imProcessZeroCrossing(const imImage* src_image, imImage* dst_image); 00336 00337 /** First part of the Canny edge detector. Includes the gaussian filtering and the nonmax suppression. \n 00338 * After using this you could apply a Hysteresis Threshold, see \ref imProcessHysteresisThreshold. \n 00339 * Image must be IM_BYTE/IM_GRAY. \n 00340 * Implementation from the book: 00341 \verbatim 00342 J. R. Parker 00343 "Algoritms for Image Processing and Computer Vision" 00344 WILEY 00345 \endverbatim 00346 * \ingroup convolve */ 00347 void imProcessCanny(const imImage* src_image, imImage* dst_image, float stddev); 00348 00349 /** Calculates the number of 3x3 gaussian repetitions given the standard deviation. 00350 * \ingroup convolve */ 00351 int imGaussianStdDev2Repetitions(float stddev); 00352 00353 /** Calculates the kernel size given the standard deviation. 00354 * \ingroup convolve */ 00355 int imGaussianStdDev2KernelSize(float stddev); 00356 00357 00358 #if defined(__cplusplus) 00359 } 00360 #endif 00361 00362 #endif