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