Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV上的逆滤波-访问DFT值并乘以DFT矩阵_C_Image Processing_Opencv_Dft - Fatal编程技术网

OpenCV上的逆滤波-访问DFT值并乘以DFT矩阵

OpenCV上的逆滤波-访问DFT值并乘以DFT矩阵,c,image-processing,opencv,dft,C,Image Processing,Opencv,Dft,我尝试在频域中执行逆滤波和伪逆滤波 然而,我在访问DFT系数和之后乘以DFT矩阵时遇到困难,因为我得到了复数,因此,实际上是两个矩阵 基本上,逆滤波执行 F=克/小时 其中F是恢复图像,G是模糊图像,H是模糊图像的核 伪逆需要访问H中的值,因为如果该值接近0,则应替换该值,以避免恢复中出现问题。为此,我们必须更改H,以便: 如果H(u,v)>阈值,则H(u,v)=1/H(u,v) 否则为0 我有一个内核1(h_1),图像imf(恢复)和img(模糊)。代码如下: // compute the

我尝试在频域中执行逆滤波和伪逆滤波

然而,我在访问DFT系数和之后乘以DFT矩阵时遇到困难,因为我得到了复数,因此,实际上是两个矩阵

基本上,逆滤波执行

F=克/小时

其中F是恢复图像,G是模糊图像,H是模糊图像的核

伪逆需要访问H中的值,因为如果该值接近0,则应替换该值,以避免恢复中出现问题。为此,我们必须更改H,以便:

如果H(u,v)>阈值,则H(u,v)=1/H(u,v) 否则为0

我有一个内核1(h_1),图像imf(恢复)和img(模糊)。代码如下:

  // compute the DFTs of the kernel (DFT_B) and the blurred image (DBF_A)
  cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput1->height );
  cvDFT( dft_B, dft_B, CV_DXT_FORWARD, complexInput2->height );

  // the first type is the inverse fitlering
  if (type == 1) {
      printf("...performing inverse filtering\n");
      // dividing the transforms
      cvDiv(dft_A, dft_B, dft_C, 1);
  }
  // the second type is the pseudo-inverse filtering
  else {
      printf("...prepare kernel for pseudo-inverse filtering\n");
      // will try to access the real values in order to see if value is above a threshold
      cvSplit( dft_B, image_Re1, image_Im1, 0, 0 );
      // pointers to access the data into the real and imaginary matrices
      uchar * dRe1 = (uchar *)image_Re1->imageData;
      uchar * dIm1 = (uchar *)image_Im1->imageData;
      int width  = image_Re1->width;
      int height = image_Re1->height;
      int step = image_Re1->widthStep;
      image_Re2 = cvCreateImage(cvGetSize(image_Re1), IPL_DEPTH_32F, 1);
      image_Im2 = cvCreateImage(cvGetSize(image_Im2), IPL_DEPTH_32F, 1);
      // pointers to access the data into the real and imaginary matrices
      // it will be the resulting pseudo-inverse filter
      uchar * dRe2 = (uchar *)image_Re2->imageData;
      uchar * dIm2 = (uchar *)image_Im2->imageData;

      printf("...building kernel for pseudo-inverse filtering\n");
      for ( i = 0; i < height; i++ )  {
      for ( j = 0; j < width; j++ ) {
                // generate the 1/H(i,j) value
        if (dRe1[i * step + j] > threshold) {
            float realsq = dRe1[i * step + j]*dRe1[i * step + j];
            float imagsq = dIm1[i * step + j]*dIm1[i * step + j];

            dRe2[i * step + j] = dRe1[i * step + j] / (realsq + imagsq);
            dIm2[i * step + j] = -1 * (dIm1[i * step + j] / (realsq + imagsq));
        }
        else {
            dRe2[i * step + j] = 0;
            dIm2[i * step + j] = 0;
        }
      }
      }
      printf("...merging final kernel\n");
      cvMerge(image_Re2, image_Im2, 0, 0, dft_B);
      printf("...performing pseudo-inverse filtering\n");
      cvMulSpectrums(dft_A, dft_B, dft_C, 1);
  }
  printf("...performing IDFT\n");
  cvDFT(dft_C, dft_H, CV_DXT_INV_SCALE, 1);

  printf("...getting size\n");
  cvGetSubRect(dft_H, &tmp3, cvRect(0, 0, img->width, img->height));

  printf("......(%d, %d) - (%d, %d)\n", tmp3.cols, tmp3.rows, restored->width, restored->height);

  cvSplit( &tmp3, image_Re1, image_Im1, 0, 0 );

  cvNamedWindow("re", 0);
  cvShowImage("re", image_Re2);
  cvWaitKey(0);

  printf("...copying final image\n");
  // error is in the line below
  cvCopy(image_Re1, imf, NULL);
//计算内核(DFT_B)和模糊图像(DBF_A)的DFT
cvDFT(dft_A、dft_A、正向CV_DXT_、复合输入1->高度);
cvDFT(dft\u B、dft\u B、正向CV\u DXT\u、复合输入2->高度);
//第一种类型是反向拟合
如果(类型==1){
printf(“…执行反向过滤\n”);
//划分变换
cvDiv(dft_A,dft_B,dft_C,1);
}
//第二类是伪逆滤波
否则{
printf(“…为伪逆过滤准备内核\n”);
//将尝试访问实际值,以查看值是否高于阈值
cvSplit(dft_B,image_Re1,image_Im1,0,0);
//将数据访问到实矩阵和虚矩阵的指针
uchar*dRe1=(uchar*)图像_Re1->图像数据;
uchar*dIm1=(uchar*)图像\u Im1->图像数据;
int width=图像_Re1->width;
int height=图像_Re1->高度;
int step=image_Re1->widthStep;
image_Re2=cvCreateImage(cvGetSize(image_Re1),IPL_DEPTH_32F,1);
image_Im2=cvCreateImage(cvGetSize(image_Im2),IPL_DEPTH_32F,1);
//将数据访问到实矩阵和虚矩阵的指针
//它将是产生的伪逆滤波器
uchar*dRe2=(uchar*)图像_Re2->图像数据;
uchar*dIm2=(uchar*)图像\u Im2->图像数据;
printf(“…为伪逆过滤构建内核\n”);
对于(i=0;i阈值){
float realsq=dRe1[i*步骤+j]*dRe1[i*步骤+j];
浮点imagsq=dIm1[i*步进+j]*dIm1[i*步进+j];
dRe2[i*step+j]=dRe1[i*step+j]/(realsq+imagsq);
dIm2[i*步骤+j]=-1*(dIm1[i*步骤+j]/(realsq+imagsq));
}
否则{
dRe2[i*step+j]=0;
dIm2[i*步进+j]=0;
}
}
}
printf(“…合并最终内核\n”);
cvMerge(image_Re2,image_Im2,0,0,dft_B);
printf(“…执行伪逆过滤\n”);
CVM谱(dft_A,dft_B,dft_C,1);
}
printf(“…正在执行IDFT\n”);
cvDFT(dft_C、dft_H、CV_DXT_INV_SCALE,1);
printf(“…正在获取大小\n”);
cvGetSubRect(dft_H,&tmp3,cvRect(0,0,img->width,img->height));
printf(“…(%d,%d)-(%d,%d)\n”,tmp3.cols,tmp3.rows,还原->宽度,还原->高度);
cvSplit(&tmp3,image_Re1,image_Im1,0,0);
cvNamedWindow(“re”,0);
cvShowImage(“re”,图像_-Re2);
cvWaitKey(0);
printf(“…复制最终图像\n”);
//错误在下面的行中
cvCopy(图像_Re1,imf,空);
我在最后一行有一个错误:--OpenCV错误:在cvCopy文件/build/buildd/OpenCV-2.1.0/src/cxcore/cxcopy.cpp的第466行,断言失败(src.depth()==dst.depth()&&src.size()==dst.size())

我知道这与大小或深度有关,但我不知道如何控制。不管怎样,我试图显示图像_Re1,但它是空的


有人能解释一下吗?

好像你没有初始化你的imf图片!
cvCopy
需要初始化矩阵执行以下操作:

IplImage* imf=   cvCreateImage(cvGetSize(image_Re1), IPL_DEPTH_32F, 1);
首先,我认为它会起作用


此外,您没有在此代码中释放图像空间
(cvReleaseImage(&image))

尝试将上述代码简化为一个仍然存在问题的最小示例-您更有可能通过这种方式得到答案。