Main Page   Data Structures   File List   Data Fields   Globals  

histogrm.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This low-level function computes the histograms for all image bands.     */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 HISTOGRM (IMAGE * in,           /*  I   Pointer to the image.                                 */
00014           short inc,            /*  I   Pixels/line and line increment.                       */
00015           PIXEL gmin,           /*  I   Minimum graylevel to use in histogram.                */
00016           PIXEL gmax,           /*  I   Maximum graylevel to use in histogram.                */
00017           short nlev,           /*  I   Number of bins in the histogram.                      */
00018           long *hist            /*  O   Pointer to the histogram array[in->nbnd*nlev].        */
00019 /*----------------------------------------------------------------------------*/
00020   )
00021 {
00022   register short i, j, k;
00023   double factor = (double) nlev / (double) (gmax - gmin + 1);
00024 
00025   if (TIMES)
00026     TIMING (T_HISTOGRM);
00027 
00028   /* compute histogram for each band, clip if necessary */
00029   for (i = 0; i < in->nbnd * nlev; i++)
00030     {
00031       hist[i] = 0L;
00032     }
00033   for (i = 0; i < in->nbnd; i++)
00034     {
00035       for (j = 0; j < in->nlin; j += inc)
00036         {
00037           for (k = 0; k < in->npix; k += inc)
00038             {
00039               if (in->data[i][j][k] <= gmin)
00040                 {
00041                   hist[i * nlev + 0] += 1L;
00042                 }
00043               else if (gmin < in->data[i][j][k] && in->data[i][j][k] < gmax)
00044                 {
00045                   hist[i * nlev +
00046                        (short) ((double) (in->data[i][j][k] - gmin) *
00047                                 factor)] += 1L;
00048                 }
00049               else
00050                 {
00051                   hist[i * nlev + nlev - 1] += 1L;
00052                 }
00053             }
00054         }
00055     }
00056 
00057 the_end:
00058   if (TIMES)
00059     TIMING (T_EXIT);
00060 }
00061 
00062 /*-Copyright Information------------------------------------------------------*/
00063 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00064 /*----------------------------------------------------------------------------*/
00065 /*-General Information--------------------------------------------------------*/
00066 /*                                                                            */
00067 /*   This low-level function computes a histograms for all image bands using  */
00068 /*   only data in the specified range.                                        */
00069 /*                                                                            */
00070 /*----------------------------------------------------------------------------*/
00071 /*-Interface Information------------------------------------------------------*/
00072 void
00073 STRICTHISTOGRM (IMAGE * in,     /*  I   Pointer to the image.                                 */
00074                 short inc,      /*  I   Pixels/line and line increment.                       */
00075                 short option,   /*  I   Switch, indicating how to use input pixel range:      */
00076                 /*      INCLUDE - Use only this input range for computing     */
00077                 /*                statistics.                                 */
00078                 /*      EXCLUDE - Exclude this pixel range.                   */
00079                 PIXEL gmin,     /*  I   Minimum graylevel in range.                           */
00080                 PIXEL gmax,     /*  I   Maximum graylevel in range.                           */
00081                 short nlev,     /*  I   Number of bins in the histogram.                      */
00082                 long *hist      /*  O   Pointer to the histogram array[in->nbnd*nlev].        */
00083 /*----------------------------------------------------------------------------*/
00084   )
00085 {
00086   register short i, j, k;
00087   double factor;
00088 
00089   if (TIMES)
00090     TIMING (T_HISTOGRM);
00091 
00092   RANGE (in);
00093 
00094   if (option == INCLUDE)
00095     {
00096       factor = (double) nlev / (double) (gmax - gmin + 1);
00097     }
00098   else
00099     {
00100       factor = (double) nlev / (double) (in->gmax - in->gmin + 1);
00101     }
00102 
00103   /* compute histogram for each band, clip if necessary */
00104   for (i = 0; i < in->nbnd * nlev; i++)
00105     {
00106       hist[i] = 0L;
00107     }
00108   for (i = 0; i < in->nbnd; i++)
00109     {
00110       for (j = 0; j < in->nlin; j += inc)
00111         {
00112           for (k = 0; k < in->npix; k += inc)
00113             {
00114               if (option == INCLUDE)
00115                 {
00116                   if (in->data[i][j][k] == gmin)
00117                     {
00118                       hist[i * nlev + 0] += 1L;
00119                     }
00120                   else if (gmin < in->data[i][j][k]
00121                            && in->data[i][j][k] < gmax)
00122                     {
00123                       hist[i * nlev +
00124                            (short) ((double) (in->data[i][j][k] - gmin) *
00125                                     factor)] += 1L;
00126                     }
00127                   else if (in->data[i][j][k] == gmax)
00128                     {
00129                       hist[i * nlev + nlev - 1] += 1L;
00130                     }
00131                 }
00132               else
00133                 {
00134                   if (in->data[i][j][k] < gmin || in->data[i][j][k] > gmax)
00135                     {
00136                       if (in->data[i][j][k] == in->gmin)
00137                         {
00138                           hist[i * nlev + 0] += 1L;
00139                         }
00140                       else if (in->data[i][j][k] == in->gmax)
00141                         {
00142                           hist[i * nlev + nlev - 1] += 1L;
00143                         }
00144                       else
00145                         {
00146                           hist[i * nlev +
00147                                (short) ((double)
00148                                         (in->data[i][j][k] -
00149                                          in->gmin) * factor)] += 1L;
00150                         }
00151                     }
00152                 }
00153             }
00154         }
00155     }
00156 
00157 the_end:
00158   if (TIMES)
00159     TIMING (T_EXIT);
00160 }

Generated on Sun May 18 15:36:10 2003 for tclSadie by doxygen1.3