 
     // testme( plane );
 
-    maxval = 255.0 / ( maxval - minval );
+    float fmaxval = 255.0 / ( (float)maxval - (float)minval );
     for( uint32_t i=0; i<plane.rows*plane.cols; i++ ) {
         T f = plane.data[i];
-        f = ( f - minval ) * maxval;
-        unsigned char uc = (unsigned char)f;
+        float outf = ( (float)f - (float)minval ) * fmaxval;
+        unsigned char uc = (unsigned char)outf;
         of << uc;
     }
 

                            getWidth() );
    writeDebugPlane1( s.c_str(), b );

    s = filename + "-gauss.pgm";
    cv::cuda::PtrStepSzf smooth( getHeight(),
                                 getWidth(),

                                 getWidth()*sizeof(float) );
    writeDebugPlane( s.c_str(), smooth );

    {
        ofstream of( ( filename + "-gauss-ascii.txt" ).c_str() );
        for( int y=0; y<getHeight(); y++ ) {
            for( int x=0; x<getWidth(); x++ )
            {
                int val = smooth.ptr(y)[x];
                of << val << " ";
            }
            of << endl;
        }
    }

    s = filename + "-dx.pgm";
    cv::cuda::PtrStepSz16s dx( getHeight(),
                               getWidth(),
