/***************************************************************************/ void make_image() { unsigned short int *pdummy,linebuf[1024],*lbp; int x,y,frame_no,value; int alfa11,alfa22,alfa12,beta1; unsigned short int *frame_offset; long int beta2; double a1,a2,a,b1,b2,A,B,pix; int imsize; imsize = im_pmaxx*im_pmaxy; last_frame_offset = imsize*brocam_info.frame_total; frame_offset = xbuf + last_frame_offset; pdummy = xbuf; // pointer to the array of (brocam_info.frame_total * imsize) short unsigned integers // First calculate the terms not depending on pixel values // // Some values are first calculated as integers, the converted to float (double) // // Compared to 'Numerical Recipes' pg 505 : // // S = alfa11 = a1 (float) // Sx = alfa12 = a // Sy = beta1 = b1 // Sxx = alfa22 = a2 // Sxy = b2 // alfa22 = 0; alfa11 = brocam_info.frame_total; // Now do 1+2+3+...+N alfa12 = ( brocam_info.frame_total + 1 ) * brocam_info.frame_total / 2; // Then 1^2+2^2+3^3+...+N^2 for ( frame_no = 0; frame_no < brocam_info.frame_total; frame_no++ ) alfa22 += (frame_no+1) * (frame_no+1); // // convert to float a1 = (double)alfa11; a2 = (double)alfa22; a = (double)alfa12; // step through frames pixel by pixel for ( y = 0; y < im_pmaxy; y++ ) { lbp = linebuf; // linebuffer for result for ( x = 0; x < im_pmaxy; x++ ) { beta1 = beta2 = 0; b2 = 0.0; // Then step through all frames on the same pixel for ( frame_no = 0; frame_no < brocam_info.frame_total; frame_no++ ) { // this gets the pixel value with pointer math value = *(pdummy+(frame_no*imsize)); beta1 += value; b2 += (double)value * (double)frame_no; } b1 = (double)beta1; B = ( ( a * b1 ) - ( a1 * b2 ) ) / ( ( a * a ) - ( a1 * a2 ) ); A = ( b1 - ( a * B ) ) / a1; /* This gives the estimated final count */ pix = 0.0 + ( B * ( brocam_info.frame_total - 1 )); if ( pix < 1.0 ) pix = 0.0; else if ( pix > 65535.0 ) pix = 65535.0; *(lbp++) = (unsigned short int)(pix+0.5); pdummy++; } // copy the resulting line to the final buffer bcopy(linebuf,frame_offset+( y * im_pmaxy),im_pmaxx*2); } }