include include include # T_DQENORMX -- generates relative DQE image, normalised to unity # # D. Giaretta, 01-Aug-1987 Original SPP version # Phil Hodge, 22-Jan-1993 Use IS_INDEF instead IS_INDEFR (of). procedure t_dqenormx() char i_imlist[SZ_LINE] # input image list char o_imlist[SZ_LINE] # output image list long x1, x2, y1, y2 # corners of rectangle to use real upper, lower # upper and lower limits of pix to use pointer i_list # input image template list pointer pointer o_list # output image template list pointer pointer imtopen() int imtgetim() pointer sp char i_image[SZ_FNAME] # single input image name char o_image[SZ_FNAME] # single output image name int imtlen() int clgeti() real clgetr() errchk clgeti, clgetr, imtlen begin call smark(sp) call clgstr("input", i_imlist, SZ_LINE) call clgstr("output", o_imlist, SZ_LINE) i_list = imtopen( i_imlist) o_list = imtopen( o_imlist) if (imtlen( i_list) != imtlen( o_list) ) { call imtclose( i_list) call imtclose( o_list) call error(0, "Input and output lists not the same size") } x1 = clgeti("x1") x2 = clgeti("x2") y1 = clgeti("y1") y2 = clgeti("y2") upper = clgetr("upper") lower = clgetr("lower") while( imtgetim( i_list, i_image, SZ_FNAME) != EOF && imtgetim( o_list, o_image, SZ_FNAME) != EOF ) { call xnormdqe( i_image, o_image, x1, x2, y1, y2, upper, lower) } call imtclose( i_list) call imtclose( o_list) call sfree(sp) end # XNORMDQE -- normalise single image procedure xnormdqe( i_image, o_image, ix1, ix2, iy1, iy2, upper, lower) char i_image[SZ_FNAME] # i: input image name char o_image[SZ_FNAME] # i: output image name long ix1, ix2, iy1, iy2 # i: corners of rectangle to use real upper, lower # i: upper and lower limits of pix to use #-- pointer i_foc_coord, o_foc_coord # foc structures for input and output pointer x_foc_immap() pointer i_im, o_im long x1, x2, y1, y2 real mean # mean of area real temp long ngood # number of good pixels in area long i_v[IM_MAXDIM], o_v[IM_MAXDIM], i, line long npix char caltype[SZ_LINE] double sum pointer linept, i_line, o_line, imgl2r() int imgnlr(), impnlr() bool streq() errchk imgl2r, imgnlr, impnlr, x_foc_immap begin # special treatment for FOC coords call salloc( i_foc_coord, SZ_FOC_COORD, TY_STRUCT) FOC_COORD_INIT(i_foc_coord) = false i_im = x_foc_immap( i_image, i_foc_coord, READ_ONLY, NULL) # check if the input image is source normalised call strcpy( EOS, caltype, SZ_LINE) iferr( call imgstr( i_im, "CALTYPE", caltype, SZ_LINE) ) ; if (!streq(caltype, "SOURCE_NORMALISED") ) { call printf( "Warning: ") call printf( IM_NAME(i_im)) call printf( " is not source normalised\n") } # set the limits for calculation of the mean if (IS_INDEFI (ix1)) x1 = 1 else x1 = ix1 if (IS_INDEFI (ix2)) x2 = IM_LEN(i_im, 1) else x2 = ix2 if (IS_INDEFI (iy1)) y1 = 1 else y1 = iy1 if (IS_INDEFI (iy2)) y2 = IM_LEN(i_im, 2) else y2 = iy2 # calculate mean value sum = 0.0 ngood = 0 for (line=y1; line<=y2; line=line+1) { linept = imgl2r( i_im, line) for (i=x1-1; i lower) ) { ngood = ngood + 1 sum = sum + temp } } } } if (ngood == 0) mean = 0.0 else mean = sum/ngood if (mean != 0.0 ) { # print mean value call printf( IM_NAME(i_im) ) call printf( " mean DN value used : %g , with %d good pixels\n") call pargr( mean) call pargi( ngood) call flush( STDOUT) call salloc( o_foc_coord, SZ_FOC_COORD, TY_STRUCT) FOC_COORD_INIT(o_foc_coord) = true FOC_PC_COORDS(o_foc_coord) = FOC_PC_COORDS(i_foc_coord) iferr (o_im = x_foc_immap( o_image, o_foc_coord, NEW_COPY, i_foc_coord ) ) { call printf( " Cannot create output file for input ") call printf( IM_NAME(i_im)) call printf( "\n") call imunmap(i_im) return } IM_PIXTYPE(o_im) = TY_REAL call amovkl(long(1), i_v, IM_MAXDIM) call amovkl(long(1), o_v, IM_MAXDIM) npix = IM_LEN(i_im, 1) while (imgnlr( i_im, i_line, i_v) != EOF && impnlr( o_im, o_line, o_v) != EOF ) call adivkr( Memr[i_line], mean, Memr[o_line], npix ) # label the output image call x_foc_out_label( o_foc_coord) call imastr( o_im, "FILETYPE", "UNIFORM DE") call imastr( o_im, "CALTYPE" , "RELATIVE_DE") call imaddr( o_im, "MEANDE", mean) call imunmap(o_im) } else { call printf( "Warning : ") call printf( IM_NAME(i_im)) call printf( " cannot be normalise - zero mean or no good pixels \n") } call imunmap(i_im) end