java opencv dct 压缩,OpenCV的 - 实现拆分和合并为DCT

I am trying to implement a DCT code in Android. I'm using the split and merge method to obtain the original colors of the image.

Here is the snippet of the code

image = Highgui.imread(imageName);

secondImage = new Mat(image.rows(), image.cols(), CvType.CV_32FC3);

image.convertTo(secondImage, CvType.CV_32FC3);

int m = Core.getOptimalDFTSize(image.rows());

int n = Core.getOptimalDFTSize(image.cols()); // on the border add zero values

Mat padded = new Mat(new Size(n, m), CvType.CV_32FC3); // expand input image to optimal size

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

List planes = new ArrayList();

Core.split(padded, planes);

List outplanes = new ArrayList(planes.size());

for (int k = 0; k < planes.size(); k++) {

outplanes.add(new Mat(padded.size(), CvType.CV_32FC1));

}

Mat trans = new Mat(padded.size(), padded.type());

for (int k = 0; k < planes.size(); k++) {

Core.dct(planes.get(k), outplanes.get(k));

}

List ioutplanes = new ArrayList(outplanes.size());

for (int k = 0; k < planes.size(); k++) {

ioutplanes.add(new Mat(padded.size(), CvType.CV_32FC1));

}

for (int k = 0; k < planes.size(); k++) {

Core.idct(outplanes.get(k), ioutplanes.get(k));

}

Core.merge(ioutplanes, trans);

This time got this exception :

The function/feature is not implemented (Odd-size DCT's are not implemented) in void cv::dct(cv::InputArray, cv::OutputArray, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/dxt.cpp, line 2330

Is this code correct? Your help is very much appreciated.

Updated: I noticed that the copyMakeBorder() is the one that caused my image size to be odd, that is why I am having this exception.

解决方案

Maybe you can change this code

int m = Core.getOptimalDFTSize(image.rows());

int n = Core.getOptimalDFTSize(image.cols());

to

int m =Core.getOptimalDFTSize((image.rows()+1)/2)*2;

int n = Core.getOptimalDFTSize((image.cols()+1)/2)*2;

in order to get the odd size for DCT, since this function is for DFT.

It is written in the function documentation from the website as this:

While the function cannot be used directly to estimate the optimal vector size for DCT transform (since the current DCT implementation supports only even-size vectors), it can be easily processed as getOptimalDFTSize((vecsize+1)/2)*2.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值