如何使用opencv android得到DFT对数谱的逆?

时间:2014-09-27 03:17:12

标签: android opencv fft dft

我是opencv和图像处理的新手。需要获得对数谱的逆傅立叶并使用opencv android访问像素的值。我在互联网上搜索,但没有找到答案。这是我的代码

Mat out=DFT(ImageMat);
Mat lastoutput=IFFT(out);


private Mat DFT (Mat singleChannel) {
int m = Core.getOptimalDFTSize(singleChannel.rows());
int n = Core.getOptimalDFTSize(singleChannel.cols()); 


Imgproc.cvtColor(singleChannel, singleChannel, Imgproc.COLOR_BGR2GRAY);


Mat padded = new Mat();
singleChannel.convertTo(singleChannel, CvType.CV_64FC2);

Imgproc.copyMakeBorder(singleChannel, padded, 0, m - singleChannel.rows(), 0,
        n - singleChannel.cols(), Imgproc.BORDER_CONSTANT);

List<Mat> planes = new ArrayList<Mat>();
planes.add(padded);
planes.add(Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1));

Mat complexI = Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1);

Mat complexI2 = Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1);

Core.merge(planes, complexI);

Core.dft(complexI, complexI2);

Core.split(complexI2, planes);

Mat mag = new Mat(planes.get(0).size(), planes.get(0).type());

Core.magnitude(planes.get(0), planes.get(1), mag); 

Mat magI = mag;
Mat magI2 = new Mat(magI.size(), magI.type());
Mat magI3 = new Mat(magI.size(), magI.type());
Mat magI4 = new Mat(magI.size(), magI.type());
Mat magI5 = new Mat(magI.size(), magI.type());

Core.add(magI, Mat.ones(padded.rows(), padded.cols(), CvType.CV_64FC1), magI2);
Core.log(magI2, magI3);

return magI3;
}

private Mat IFFT (Mat res) {
Mat padded = new Mat();

int m = Core.getOptimalDFTSize(res.rows());
int n = Core.getOptimalDFTSize(res.cols()); 

Imgproc.copyMakeBorder(res, padded, 0, m - res.rows(), 0, n - res.cols(), Imgproc.BORDER_CONSTANT);

List<Mat> planes = new ArrayList<Mat>();
planes.add(padded);
planes.add(Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1));

Mat complexI = Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1);

Mat complexI2 = Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1);

Core.merge(planes, complexI);

//Core.idft(complexI, complexI2);
Core.idft(complexI, complexI2, Core.DFT_COMPLEX_OUTPUT + Core.DFT_SCALE, res.rows());

Core.split(complexI2, planes);
complexI2= planes.get(0);

return complexI2;   
}

但是,IDFT的像素输出值似乎很奇怪。我做错了什么?

0 个答案:

没有答案