Main Page   Data Structures   File List   Data Fields   Globals  

setmean.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "proto.h"
00003 
00004 
00005 extern  PIXEL   gain;
00006 extern  PIXEL   bias;
00007 
00008 /*-Copyright Information------------------------------------------------------*/
00009 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00010 /*----------------------------------------------------------------------------*/
00011 /*-General Information--------------------------------------------------------*/
00012 /*                                                                            */
00013 /*   This function stretches an image such that it has a given mean value.    */
00014 /*                                                                            */
00015 /*----------------------------------------------------------------------------*/
00016 /*-Interface Information------------------------------------------------------*/
00017 void SETMEAN (
00018 IMAGE *in,      /*  I   Pointer to the input image.                           */
00019 PIXEL mean,     /*  I   The desired resulting mean value.                     */
00020 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00021 /*----------------------------------------------------------------------------*/
00022 ) { register short i, j, k;
00023     char   msg[SLEN];
00024     double sum, adj;
00025 
00026     if (TIMES) TIMING(T_RGBTOHSV);
00027     if (NAMES) {
00028         MESSAGE('I',"");
00029         MESSAGE('I',"SETMEAN");
00030         MESSAGE('I',"");
00031         sprintf(msg," Input image:   %s",in->text);
00032         MESSAGE('I',msg);
00033         MESSAGE('I'," ...............");
00034     }
00035 
00036     /* check input */
00037     if (!CHECKIMG(in)) {
00038         MESSAGE('E'," Can't identify image.");
00039         goto the_end;
00040     }
00041 
00042     for (i=0; i<in->nbnd; i++) {
00043         sum = 0.0;
00044         for (j=0; j<in->nlin; j++) {
00045             for (k=0; k<in->npix; k++) {
00046                 sum += (double) in->data[i][j][k];
00047             }
00048         }
00049     }
00050     sum /= (double)(in->nbnd) * (double)(in->nlin) * (double)(in->npix);
00051     adj = (double)mean - sum;
00052 
00053     bias = (PIXEL) adj;
00054     gain = (PIXEL) 1.0;
00055     STRETCH(in, TFLINEAR, out);
00056     
00057     
00058 
00059     the_end:
00060     if (TIMES) TIMING(T_EXIT);
00061 }

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