Next: Creating a new image
Up: Examples of using IMG from C
Previous: Examples of using IMG from C
This section shows a C version of the mean program from
elsewhere.
#include <stdio.h>
#include "img.h" [1]
void mean_(int *istat) [2]
{
/* Local variables: */
float *ip, sum;
int nx, ny, i;
/* Access the input image. */
imgIn( "in", &nx, &ny, &ip, istat );
/* Derive the mean and write it out. */
sum = 0.0f;
for( i=0; i < nx*ny; i++ ) sum += ip[i];
printf ("Mean value = %f\n", sum/(nx*ny) );
/* Free the input image. */
imgFree( "in", istat );
}
The following notes refer to the numbered statements:
- 1.
- The file img.h contains prototypes of all the IMG
and HDR functions.
- 2.
- As in the Fortran case this program needs to be created as a
function with an int * argument. This is a replacement for
the main function. Note that the function is named the same
as the eventual program except for the trailing underscore. The
underscore is required as this function will be called from a Fortran
subroutine (you should also note that this ``trick'' may not be the
same from machine to machine, to do this portably you should use the
CNF (SUN/209) macros as in the full example of
mean.c).
As before an interface file -
mean.ifl
- is also required to complete the program.
Next: Creating a new image
Up: Examples of using IMG from C
Previous: Examples of using IMG from C
IMG Simple Image Data Access
Starlink User Note 160
P.W. Draper
R.F. Warren-Smith
3 March 2003
E-mail:P.W.Draper@durham.ac.uk
Copyright © 2000-2003 Council for the Central Laboratory of the Research Councils