Error in linsolve
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);
This gives:
error >>??? Error using ==> linsolve
First and second arguments must be single or double.
Error in ==> test at 9
A1= linsolve(b,x1,opts);
Please he开发者_StackOverflow社区lp to resolve this.
Also is there any other method to solve an Equation of the form say Eq1= A*2.1 + B*3.5 +C*1.5
?
I think the problem is with the dimensions, not with the arguments. The following code works for me:
% 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);
[edit] to @SKM and @gary, here's a detailed solution (for the RGB case):
% 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');
精彩评论