资源简介
对于受损的图像可以通过算法将其还原,因为用到的是从外圈到里圈的逐层修复,所以修复效果比较不错,可以通过对PSNR值的计算,得到图像修复的好坏。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#ifdef _CH_
#pragma package
#endif
IplImage* img0 = 0 *img = 0 *mask = 0*abc*abc0;
IplImage* Img_repair=0;
IplImage* Img_cvrepair=0;
IplImage* Mask=0;
IplImage* Abc=0;
IplImage* Mask0=0;
CvPoint prev_pt = {-1-1};
struct node{
int x;
int y;
int px[3];
struct node *pNext;
};
void on_mouse( int event int x int y int flags void* zhang)
{
if ( !img )
return;
if (event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON) )
prev_pt = cvPoint(-1-1);
else if (event == CV_EVENT_LBUTTONDOWN)
prev_pt = cvPoint(xy);
else if (event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON) )
{
CvPoint pt = cvPoint(xy);
if (prev_pt.x < 0)
prev_pt = pt;
cvLine(img prev_pt pt CV_RGB(255 255 255) 5);
cvLine(mask prev_pt pt cvScalarAll(255) 5 8);
prev_pt = pt;
cvShowImage(“Damaged Image“ img );
}
}
void psnr(IplImage* src1 IplImage* src2)
{
int h1 = src1->height;
int w1 = src1->width;
int c1 = src1->nChannels;
int h2 = src2->height;
int w2 = src2->width;
int c2 = src2->nChannels;
int step;
int i j k;
double sub;
double mse = 0;
double psnr_value;
uchar *data1;
uchar *data2;
if ( (h1 != h2) || (w1 != w2) || (c1 != c2) )
{
printf(“Warning : The dimension of two input images must be the same!\n\n“);
}
else
{
step = src1->widthStep;
data1 = (uchar *)src1->imageData;
data2 = (uchar *)src2->imageData;
for ( i = 0; i < h1 ; i++)
{
for ( j = 0; j < w1 ; j++)
{
for ( k = 0; k < c1 ; k++ )
{
sub = abs(data1[i*step+j*c1+k] - data2[i*step+j*c2+k]);
mse = mse + pow(sub 2);
}
}
}
if (mse == 0)
{
printf(“PSNR is infinite. They may be the same images.\n\n“);
}
else
{
mse = mse/h1/w1/c1;
psnr_value = 10*log10(pow(255.0 2)/mse);
printf(“PSNR = %.2f dB\n\n“ psnr_value);
}
}
}
struct node *Get_Px (IplImage* Img) //创建结构体储存外围坏点位置
{
int k=0;
bool one=falsetwo=false;
uchar *Data=(uchar *)Img->imageData;
int step_mark=Img->widthStep/sizeof(uchar);
struct node *pHead=NULL*pPail=NULL;
for (int i=0; iheight; i++)
{
for (int j=0; jwidth; j++)
{
one=(i==0)||(j==0)||(i==(Img->height-1))||(j==(Img->width-1)); //判断是否为最外围像素
if(one==false)
two=(Data[i*step_mark+j-1]==0)||(Data[i*step_mark+j+1]==0)||(Data[(i-1)*step_mark+j]==0)||(Data[(i+1)*step_mark+j]==0); //判断该点是否有相邻好点
if((Data[i*step_mark+j]==255)&&one)
{
k++;
struct no
评论
共有 条评论