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 HISTOGRM (
00013 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 ) { register short i, j, k;
00021     double factor=(double)nlev/(double)(gmax-gmin+1);
00022 
00023     if (TIMES) TIMING(T_HISTOGRM);
00024 
00025     /* compute histogram for each band, clip if necessary */
00026     for (i=0; i<in->nbnd*nlev; i++) {
00027         hist[i] = 0L;
00028     }
00029     for (i=0; i<in->nbnd; i++) {
00030         for (j=0; j<in->nlin; j+=inc) {
00031             for (k=0; k<in->npix; k+=inc) {
00032                 if (in->data[i][j][k] <= gmin) {
00033                     hist[i*nlev+0] += 1L;
00034                 } else if (gmin < in->data[i][j][k]  &&  in->data[i][j][k] < gmax) {
00035                     hist[i*nlev+(short)((double)(in->data[i][j][k]-gmin)*factor)] += 1L;
00036                 } else {
00037                     hist[i*nlev+nlev-1] += 1L;
00038                 }
00039             }
00040         }
00041     }
00042 
00043     the_end:
00044     if (TIMES) TIMING(T_EXIT);
00045 }
00046 
00047 
00048 
00049 /*-Copyright Information------------------------------------------------------*/
00050 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00051 /*----------------------------------------------------------------------------*/
00052 /*-General Information--------------------------------------------------------*/
00053 /*                                                                            */
00054 /*   This low-level function computes a histograms for all image bands using  */
00055 /*   only data in the specified range.                                        */
00056 /*                                                                            */
00057 /*----------------------------------------------------------------------------*/
00058 /*-Interface Information------------------------------------------------------*/
00059 void STRICTHISTOGRM (
00060 IMAGE *in,      /*  I   Pointer to the image.                                 */
00061 short inc,      /*  I   Pixels/line and line increment.                       */
00062 short  option,  /*  I   Switch, indicating how to use input pixel range:      */
00063                 /*      INCLUDE - Use only this input range for computing     */
00064                 /*                statistics.                                 */
00065                 /*      EXCLUDE - Exclude this pixel range.                   */
00066 PIXEL gmin,     /*  I   Minimum graylevel in range.                           */
00067 PIXEL gmax,     /*  I   Maximum graylevel in range.                           */
00068 short nlev,     /*  I   Number of bins in the histogram.                      */
00069 long  *hist     /*  O   Pointer to the histogram array[in->nbnd*nlev].        */
00070 /*----------------------------------------------------------------------------*/
00071 ) {
00072     register short i, j, k;
00073     double factor;
00074 
00075     if (TIMES) TIMING(T_HISTOGRM);
00076 
00077     RANGE(in);
00078     
00079     if (option == INCLUDE) {
00080         factor = (double)nlev/(double)(gmax-gmin+1);
00081     } else {
00082         factor = (double)nlev/(double)(in->gmax-in->gmin+1);
00083     }
00084 
00085     /* compute histogram for each band, clip if necessary */
00086     for (i=0; i<in->nbnd*nlev; i++) {
00087         hist[i] = 0L;
00088     }
00089     for (i=0; i<in->nbnd; i++) {
00090         for (j=0; j<in->nlin; j+=inc) {
00091             for (k=0; k<in->npix; k+=inc) {
00092                 if (option == INCLUDE) {
00093                     if (in->data[i][j][k] == gmin) {
00094                         hist[i*nlev+0] += 1L;
00095                     } else if (gmin < in->data[i][j][k]  &&  in->data[i][j][k] < gmax) {
00096                         hist[i*nlev+(short)((double)(in->data[i][j][k]-gmin)*factor)] += 1L;
00097                     } else if (in->data[i][j][k] == gmax) {
00098                         hist[i*nlev+nlev-1] += 1L;
00099                     }
00100                 } else {
00101                     if (in->data[i][j][k] < gmin || in->data[i][j][k] > gmax) {
00102                         if (in->data[i][j][k] == in->gmin) {
00103                             hist[i*nlev+0] += 1L;
00104                         } else if (in->data[i][j][k] == in->gmax) {
00105                             hist[i*nlev+nlev-1] += 1L;
00106                         } else {
00107                             hist[i*nlev+(short)((double)(in->data[i][j][k]-in->gmin)*factor)] += 1L;
00108                         }
00109                     }
00110                 }
00111             }
00112         }
00113     }
00114 
00115     the_end:
00116     if (TIMES) TIMING(T_EXIT);
00117 }

Generated on Wed Apr 9 08:56:06 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002