读书人

opencv 图像增强Retinex 不会写调用解

发布时间: 2013-10-27 15:21:50 作者: rapoo

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 );
}

[解决办法]
你把全部的代码发给我,我告诉 你,我也成研究呢。
[解决办法]
如果是程序运行错误,那就把代码贴上来,大家帮你调试修改,很快的。
[解决办法]
我刚调好一个SSR的程序,要么?
[解决办法]

引用:
我刚调好一个SSR的程序,要么?
你好,您调好的SSR能发我一份吗? 867090291@qq.com. 多谢!

读书人网 >图形图像

热点推荐