opencv 图像增强Retinex 不会写调用
急用opencv的图像增强处理Retinex 但我不会调用 求大牛帮忙!
void MultiScaleRetinexCR(IplImage *img, int scales, double *weights, double *sigmas,
int gain, int offset, double restoration_factor, double color_gain)
{
int i;
double weight;
IplImage *A, *B, *C, *fA, *fB, *fC, *fsA, *fsB, *fsC, *fsD, *fsE, *fsF;
// Initialize temp images
fA = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, img->nChannels);
fB = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, img->nChannels);
fC = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, img->nChannels);
fsA = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
fsB = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
fsC = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
fsD = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
fsE = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
fsF = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, 1);
// Compute log image
cvConvert( img, fB );
cvLog( fB, fA );
// Normalize according to given weights
for (i = 0, weight = 0; i < scales; i++)
weight += weights[i];
if (weight != 1.0) cvScale( fA, fA, weight );
// Filter at each scale
for (i = 0; i < scales; i++) {
A = cvCloneImage( img );
FastFilter( A, sigmas[i] );
cvConvert( A, fB );
cvLog( fB, fC );
cvReleaseImage( &A );
// Compute weighted difference
cvScale( fC, fC, weights[i] );
cvSub( fA, fC, fA );
}
// Color restoration
if (img->nChannels > 1) {
A = cvCreateImage(cvSize(img->width, img->height), img->depth, 1);
B = cvCreateImage(cvSize(img->width, img->height), img->depth, 1);
C = cvCreateImage(cvSize(img->width, img->height), img->depth, 1);
// Divide image into channels, convert and store sum
cvCvtPixToPlane( img, A, B, C, NULL );
cvConvert( A, fsA );
cvConvert( B, fsB );
cvConvert( C, fsC );
cvReleaseImage( &A );
cvReleaseImage( &B );
cvReleaseImage( &C );
// Sum components
cvAdd( fsA, fsB, fsD );
cvAdd( fsD, fsC, fsD );
// Normalize weights
cvDiv( fsA, fsD, fsA, restoration_factor);
cvDiv( fsB, fsD, fsB, restoration_factor);
cvDiv( fsC, fsD, fsC, restoration_factor);
cvConvertScale( fsA, fsA, 1, 1 );
cvConvertScale( fsB, fsB, 1, 1 );
cvConvertScale( fsC, fsC, 1, 1 );
// Log weights
cvLog( fsA, fsA );
cvLog( fsB, fsB );
cvLog( fsC, fsC );
// Divide retinex image, weight accordingly and recombine
cvCvtPixToPlane( fA, fsD, fsE, fsF, NULL );
cvMul( fsD, fsA, fsD, color_gain);
cvMul( fsE, fsB, fsE, color_gain );
cvMul( fsF, fsC, fsF, color_gain );
cvCvtPlaneToPix( fsD, fsE, fsF, NULL, fA );
}
// Restore
cvConvertScale( fA, img, gain, offset);
// Release temp images
cvReleaseImage( &fA );
cvReleaseImage( &fB );
cvReleaseImage( &fC );
cvReleaseImage( &fsA );
cvReleaseImage( &fsB );
cvReleaseImage( &fsC );
cvReleaseImage( &fsD );
cvReleaseImage( &fsE );
cvReleaseImage( &fsF );
}