【发布时间】:2014-06-23 22:36:02
【问题描述】:
我想在 Visual Studio 中用 c++ 编写一个带有 opencv 的程序。
我的代码遵循 matlab 代码:
close all
clear all
clc
%reading and converting the image
inImage=imread('pic.jpg');
inImageD=double(inImage);
[U,S,V]=svd(inImageD);
% Using different number of singular values (diagonal of S) to compress and
% reconstruct the image
dispEr = [];
numSVals = [];
for N=5:25:300
% store the singular values in a temporary var
C = S;
% discard the diagonal values not required for compression
C(N+1:end,:)=0;
C(:,N+1:end)=0;
% Construct an Image using the selected singular values
D=U*C*V';
% display and compute error
figure;
buffer = sprintf('Image output using %d singular values', N)
imshow(uint8(D));
title(buffer);
error=sum(sum((inImageD-D).^2));
% store vals for display
dispEr = [dispEr; error];
numSVals = [numSVals; N];
end
您对此有何看法?我想将图像保存在文本文件中并将其从文件中检索到 Mat 数组中。我把这部分写成如下:
Mat image;
FileStorage read_file("pic_file.txt", FileStorage::READ);
read_file["pic"] >> image;
read_file.release();
Mat P;
image.convertTo(P, CV_32FC3,1.0/255);
SVD svda(P); //or SVD::compute(P,W,U,V);
但是我的 SVD 函数有问题,它不起作用。计算图像的 SVD 压缩有什么可做的吗?
非常感谢。
瓦希德人。
【问题讨论】:
-
“它不起作用”不足以让我们诊断您的问题。