matlab - linsolve 错误

标签 matlab matrix-multiplication

A=imread('lena_color.jpg');
x1=2.1;
b=A*x1;
b=double(b);
x1=double(x1);
opts.UT = true; opts.TRANSA = false;
A1 = linsolve(x1,b,opts);
figure;
imshow(A1);

这给出:

 error >>??? Error using ==> linsolve
First and second arguments must be single or double.

Error in ==> test at 9
A1= linsolve(b,x1,opts);

请帮助解决这个问题。

还有没有其他方法可以求解形式为 Eq1= A*2.1 + B*3.5 +C*1.5 的方程?

最佳答案

我认为问题出在尺寸上,而不是参数上。 以下代码对我有用:

% you can switch it with your own image after you see it works
I = imread('cameraman.tif');
A = im2double(I);

% scalar*matrix works in matlab commandline,
% but needs to be defined when it comes to equations
x1=2.1*eye(size(A));
b=A*x1;

opts.UT = true; 
opts.TRANSA = false;
A1 = linsolve(x1,b,opts);

figure; imshow(A1);

[编辑]@SKM 和@gary,这里有一个详细的解决方案(针对 RGB 情况):

% example for RGB image
Img= im2double( imread('peppers.png') );
Dim = size(Img, 3);

% transform the original image, 
% by multiplying every color channel by different scalar.
% that is going to be a very red image...
a = [1 0.5 0.2]; 
aMat = []; newImg = [];
for Ind=1:Dim
    aMat(:, :, Ind) = a(Ind)*eye( size(Img, 1), size(Img, 2) );
    newImg(:, :, Ind) = a(Ind)*squeeze(Img(:, :, Ind));
end

% recontructing original image
recontrcutedImg=[];
for Ind=1:Dim
    recontrcutedImg(:, :, Ind) = linsolve( aMat(:, :, Ind), newImg(:, :, Ind) );
end

% show the images
figure;
subplot(1, 3, 1); imagesc(Img); title('original');
subplot(1, 3, 2); imagesc(newImg); title('changed image');
subplot(1, 3, 3); imagesc(recontrcutedImg); title('reconstructed image');

关于matlab - linsolve 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337027/

相关文章:

c++ - 使用一维数组的矩阵乘法

algorithm - 对于给定的 n,如何找到具有以下递推关系的序列中的第 n 项?

python - tensorflow :将矩阵的某些行与另一个矩阵中的某些列相乘

algorithm - 如何从邻接矩阵matlab中获取距离矩阵

algorithm - Matlab 在 SVD 中使用哪种算法?

Matlab 和 C 使用套接字进行通信

java - 为什么减少循环次数并不能加快程序速度?

matlab - 求 3 个数字之间的最小值

matlab - 如何组合多个 MATLAB GUI

c - 对多线程应用程序使用 perf stat