简体   繁体   English

如何在JavaCV / OpenCV中进行PCA图像压缩

[英]How to do PCA Image Compression in JavaCV / OpenCV

I am tyring to do image compression in javacv /opencv. 我打算在javacv / opencv中进行图像压缩。

Firts the code: 过滤代码:

CanvasFrame canvasOrig = new CanvasFrame("Original");
canvasOrig.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

CanvasFrame canvasOrig = new CanvasFrame("Original");
canvasOrig.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

CanvasFrame canvasGray = new CanvasFrame("Gray");
canvasGray.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

CanvasFrame canvasPCA = new CanvasFrame("PCA");
canvasPCA.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

OpenCVFrameConverter.ToIplImage t = new OpenCVFrameConverter.ToIplImage();
IplImage image = cvLoadImage("640x480.jpg");

Mat imageOriginal = t.convertToMat(t.convert(image));   
Mat imageGray = new Mat();
cvtColor(imageOriginal, imageGray, CV_RGB2GRAY);
System.out.println("ArraySize-Original-Mat: "+imageGray.arraySize());

PCA pca = new PCA(imageGray,new Mat(), CV_PCA_DATA_AS_ROW, 48);
Mat eigValues = pca.eigenvalues().clone();
Mat eigVectors = pca.eigenvectors().clone();

Mat projectedMat = new Mat();
pca.project(imageGray, projectedMat);

During PCA calculating the process and the methods are bahaving like I would expect. 在PCA期间,计算过程和方法都像我期望的那样运转。

My Question is: 我的问题是:

How could I compress the original Image from the results of the PCA? 如何从PCA的结果压缩原始图像?

After the projection I get a Mat (projectedMat) with the number of given components and the height of the image. 投影后,我得到一个Mat(projectedMat),其中包含给定分量的数量和图像的高度。 After backProjection the ArraySize is much higher than the original Image. backProjection之后,ArraySize比原始Image高得多。 That is not what I did expect. 那不是我所期望的。

Thanks 谢谢

I found the answer for myself. 我为自己找到了答案。

The problem or in this context the solutions was to convert the image to type 32F oder 64F for floating point operations. 问题或在此情况下的解决方案是将图像转换为类型32F或64F的浮点运算。

After calculationg pca the image or even matrix has to be converted back to type 8 bit numbers. 在计算g pca之后,图像或什至矩阵必须转换回类型8位数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM