IM: im_process_ana.h Source File

IM - An Imaging Tool

im_process_ana.h

Go to the documentation of this file.
00001 /** \file
00002  * \brief Image Statistics and Analysis
00003  *
00004  * See Copyright Notice in im_lib.h
00005  * $Id: im_process_ana.h,v 1.2 2005/06/06 18:12:14 scuri Exp $
00006  */
00007 
00008 #ifndef __IM_PROC_ANA_H
00009 #define __IM_PROC_ANA_H
00010 
00011 #include "im_image.h"
00012 
00013 #if defined(__cplusplus)
00014 extern "C" {
00015 #endif
00016 
00017 
00018 
00019 /** \defgroup stats Image Statistics Calculations
00020  * \par
00021  * Operations to calculate some statistics over images.
00022  * \par
00023  * See \ref im_process_ana.h
00024  * \ingroup process */
00025 
00026 /** Calculates the RMS error between 2 images (Root Mean Square Error).
00027  * \ingroup stats */
00028 float imCalcRMSError(const imImage* image1, const imImage* image2);
00029 
00030 /** Calculates the SNR of an image and its noise (Signal Noise Ratio).
00031  * \ingroup stats */
00032 float imCalcSNR(const imImage* src_image, const imImage* noise_image);
00033 
00034 /** Count the number of different colors in an image. \n
00035  * Image must be IM_BYTE, but all color spaces except IM_CMYK.
00036  * \ingroup stats */
00037 unsigned long imCalcCountColors(const imImage* src_image);
00038 
00039 /** Calculates the histogram of a IM_BYTE data. \n
00040  * Histogram is always 256 positions long. \n
00041  * When cumulative is different from zero it calculates the cumulative histogram.
00042  * \ingroup stats */
00043 void imCalcHistogram(const unsigned char* data, int count, unsigned long* histo, int cumulative);
00044 
00045 /** Calculates the histogram of a IM_USHORT data. \n
00046  * Histogram is always 65535 positions long. \n
00047  * When cumulative is different from zero it calculates the cumulative histogram.
00048  * \ingroup stats */
00049 void imCalcUShortHistogram(const unsigned short* data, int count, unsigned long* histo, int cumulative);
00050 
00051 /** Calculates the gray histogram of an image. \n
00052  * Image must be IM_BYTE/(IM_RGB, IM_GRAY, IM_BINARY or IM_MAP). \n
00053  * If the image is IM_RGB then the histogram of the luma component is calculated. \n
00054  * Histogram is always 256 positions long. \n
00055  * When cumulative is different from zero it calculates the cumulative histogram.
00056  * \ingroup stats */
00057 void imCalcGrayHistogram(const imImage* src_image, unsigned long* histo, int cumulative);
00058 
00059 /** Numerical Statistics Structure
00060  * \ingroup stats */
00061 typedef struct _imStats
00062 {
00063   float max;                /**< Maximum value              */
00064   float min;                /**< Minimum value              */
00065   unsigned long positive;   /**< Number of Positive Values  */
00066   unsigned long negative;   /**< Number of Negative Values  */
00067   unsigned long zeros;      /**< Number of Zeros            */
00068   float mean;               /**< Mean                       */
00069   float stddev;             /**< Standard Deviation         */
00070 } imStats;
00071 
00072 /** Calculates the statistics about the image data. \n
00073  * There is one stats for each depth plane. For ex: stats[0]=red stats, stats[0]=green stats, ... \n
00074  * Supports all data types except IM_COMPLEX. \n
00075  * \ingroup stats */
00076 void imCalcImageStatistics(const imImage* src_image, imStats* stats);
00077 
00078 /** Calculates the statistics about the image histogram data.\n
00079  * There is one stats for each depth plane. For ex: stats[0]=red stats, stats[0]=green stats, ... \n
00080  * Only IM_BYTE images are supported.
00081  * \ingroup stats */
00082 void imCalcHistogramStatistics(const imImage* src_image, imStats* stats);
00083 
00084 /** Calculates some extra statistics about the image histogram data.\n
00085  * There is one stats for each depth plane. \n
00086  * Only IM_BYTE images are supported. \n
00087  * mode will be -1 if more than one max is found.
00088  * \ingroup stats */
00089 void imCalcHistoImageStatistics(const imImage* src_image, int* median, int* mode);
00090 
00091 
00092 
00093 /** \defgroup analyze Image Analysis
00094  * \par
00095  * See \ref im_process_ana.h
00096  * \ingroup process */
00097 
00098 /** Find white regions in binary image. \n
00099  * Result is IM_USHORT type. Regions can be 4 connected or 8 connected. \n
00100  * Returns the number of regions found. Background is marked as 0. \n
00101  * Regions touching the border are considered only if touch_border=1.
00102  * \ingroup analyze */
00103 int imAnalyzeFindRegions(const imImage* src_image, imImage* dst_image, int connect, int touch_border);
00104 
00105 /** Measure the actual area of all regions. Holes are not included. \n
00106  * This is the number of pixels of each region. \n
00107  * Source image is IM_USHORT type (the result of \ref imAnalyzeFindRegions). \n
00108  * data has size the number of regions.
00109  * \ingroup analyze */
00110 void imAnalyzeMeasureArea(const imImage* image, int* area);
00111 
00112 /** Measure the polygonal area limited by the perimeter line of all regions. Holes are not included. \n
00113  * Notice that some regions may have polygonal area zero. \n
00114  * Source image is IM_USHORT type (the result of \ref imAnalyzeFindRegions). \n
00115  * data has size the number of regions.
00116  * \ingroup analyze */
00117 void imAnalyzeMeasurePerimArea(const imImage* image, float* perimarea);
00118 
00119 /** Calculate the centroid position of all regions. Holes are not included. \n
00120  * Source image is IM_USHORT type (the result of \ref imAnalyzeFindRegions). \n
00121  * data has size the number of regions. If area is NULL will be internally calculated.
00122  * \ingroup analyze */
00123 void imAnalyzeMeasureCentroid(const imImage* image, const int* area, int region_count, float* cx, float* cy);
00124 
00125 /** Calculate the principal major axis slope of all regions. \n
00126  * Source image is IM_USHORT type (the result of \ref imAnalyzeFindRegions). \n
00127  * data has size the number of regions. If area or centroid are NULL will be internally calculated. \n
00128  * Principal (major and minor) axes are defined to be those axes that pass through the
00129  * centroid, about which the moment of inertia of the region is, respectively maximal or minimal.
00130  * \ingroup analyze */
00131 void imAnalyzeMeasurePrincipalAxis(const imImage* image, const int* data_area, const float* cx, const float* cy, 
00132                                    const int region_count, float* major_slope, float* major_length, 
00133                                                            float* minor_slope, float* minor_length);
00134 
00135 /** Measure the number and area of holes of all regions. \n
00136  * Source image is IM_USHORT type (the result of \ref imAnalyzeFindRegions). \n
00137  * data has size the number of regions. If some data is NULL it will be not calculated.
00138  * \ingroup analyze */
00139 void imAnalyzeMeasureHoles(const imImage* image, int connect, int* holes_count, int* area, float* perim);
00140 
00141 /** Measure the total perimeter of all regions (external and internal). \n
00142  * Source image is IM_USHORT type (the result of imAnalyzeFindRegions). \n
00143  * It uses a half-pixel inter distance for 8 neighboors in a perimeter of a 4 connected region. \n
00144  * This function can also be used to measure line lenght. \n
00145  * data has size the number of regions.
00146  * \ingroup analyze */
00147 void imAnalyzeMeasurePerimeter(const imImage* image, float* perim);
00148 
00149 /** Isolates the perimeter line of gray integer images. Background is defined as being black (0). \n
00150  * It just checks if at least one of the 4 connected neighboors is non zero. Image borders are extended with zeros.
00151  * \ingroup analyze */
00152 void imProcessPerimeterLine(const imImage* src_image, imImage* dst_image);
00153 
00154 /** Eliminates regions that have size outside the given interval. \n
00155  * Source and destiny are a binary images. Regions can be 4 connected or 8 connected. \n
00156  * Can be done in-place. end_size can be zero to ignore big objects.
00157  * \ingroup analyze */
00158 void imProcessPrune(const imImage* src_image, imImage* dst_image, int connect, int start_size, int end_size);
00159 
00160 /** Fill holes inside white regions. \n
00161  * Source and destiny are a binary images. Regions can be 4 connected or 8 connected. \n
00162  * Can be done in-place. 
00163  * \ingroup analyze */
00164 void imProcessFillHoles(const imImage* src_image, imImage* dst_image, int connect);
00165 
00166 
00167 #if defined(__cplusplus)
00168 }
00169 #endif
00170 
00171 #endif