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/