ImageUtils.cpp
IplImage* convertFloatImageToUcharImage(const IplImage *srcImg)
{
	IplImage *dstImg = 0;
	if ((srcImg) && (srcImg->width > 0 && srcImg->height > 0)) {

		// Spread the 32bit floating point pixels to fit within 8bit pixel range.
		double minVal, maxVal;
		cvMinMaxLoc(srcImg, &minVal, &maxVal);

		cout << "FloatImage:(minV=" << minVal << ", maxV=" << maxVal << ")." << endl;

		// Deal with NaN and extreme values, since the DFT seems to give some NaN results.
		if (cvIsNaN(minVal) || minVal < -1e30)
			minVal = -1e30;
		if (cvIsNaN(maxVal) || maxVal > 1e30)
			maxVal = 1e30;
		if (maxVal-minVal == 0.0f)
			maxVal = minVal + 0.001;	// remove potential divide by zero errors.

		// Convert the format
		dstImg = cvCreateImage(cvSize(srcImg->width, srcImg->height), 8, 1);
		cvConvertScale(srcImg, dstImg, 255.0 / (maxVal - minVal), - minVal * 255.0 / (maxVal-minVal));
	}
	return dstImg;
}
// Get an 8-bit equivalent of the 32-bit Float image.
// Returns a new image, so remember to call 'cvReleaseImage()' on the result.

Get an 8-bit equivalent of the 32-bit Float image.
Returns a new image, so remember to call 'cvReleaseImage()' on the result.
Get an 8 - bit equivalent of the 32 - bit Float image . Returns a new image so remember to call ' cvReleaseImage () ' on the result .
IplImage* convertFloatImageToUcharImage(const IplImage *srcImg)
{
	IplImage *dstImg = 0;
	if ((srcImg) && (srcImg->width > 0 && srcImg->height > 0)) {
		double minVal, maxVal;
		cvMinMaxLoc(srcImg, &minVal, &maxVal);
		cout << "FloatImage:(minV=" << minVal << ", maxV=" << maxVal << ")." << endl;
		if (cvIsNaN(minVal) || minVal < -1e30)
			minVal = -1e30;
		if (cvIsNaN(maxVal) || maxVal > 1e30)
			maxVal = 1e30;
		if (maxVal-minVal == 0.0f)
			maxVal = minVal + 0.001;	
		dstImg = cvCreateImage(cvSize(srcImg->width, srcImg->height), 8, 1);
		cvConvertScale(srcImg, dstImg, 255.0 / (maxVal - minVal), - minVal * 255.0 / (maxVal-minVal));
	}
	return dstImg;
}
IplImage * convertFloatImageToUcharImage ( const IplImage * srcImg ) { IplImage * dstImg = 0 ; if ( ( srcImg ) && ( srcImg -> width > 0 && srcImg -> height > 0 ) ) { double minVal , maxVal ; cvMinMaxLoc ( srcImg , & minVal , & maxVal ) ; cout << " " << minVal << " " << maxVal << " " << endl ; if ( cvIsNaN ( minVal ) || minVal < -1e30 ) minVal = -1e30 ; if ( cvIsNaN ( maxVal ) || maxVal > 1e30 ) maxVal = 1e30 ; if ( maxVal - minVal == 0.0f ) maxVal = minVal + 0.001 ; dstImg = cvCreateImage ( cvSize ( srcImg -> width , srcImg -> height ) , 8 , 1 ) ; cvConvertScale ( srcImg , dstImg , 255.0 / ( maxVal - minVal ) , - minVal * 255.0 / ( maxVal - minVal ) ) ; } return dstImg ; }
Get an 8-bit equivalent of the 32-bit Float image.
Get an 8 - bit equivalent of the 32 - bit Float image .
// Spread the 32bit floating point pixels to fit within 8bit pixel range.
 // Deal with NaN and extreme values, since the DFT seems to give some NaN results.
 // remove potential divide by zero errors.
 // Convert the format
