【问题标题】:Error in linsolvelinsolve 中的错误
【发布时间】:2011-03-17 09:15:36
【问题描述】:
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 形式的方程吗?

【问题讨论】:

    标签: matlab matrix-multiplication


    【解决方案1】:

    我认为问题在于尺寸,而不是论据。 以下代码适用于我:

    % 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');
    

    【讨论】:

    • @gary:该代码适用于灰度。但是,它给出了 RGB 的错误 >>???使用 ==> eye Unknown 命令选项时出错。 ==> 在 5 x1=2.1*eye(size(A)) 处测试时出错;此外,如果系数(x's) 也是二维矩阵,则结果不同,即求解线性方程时的运算不是可逆运算。如何解决这个问题?感谢您的时间和耐心。
    • 在 matlab 中求解多维可能很棘手,因为如果 A 不是 2D,answer = A\b 将不起作用。也许你可以试试I = rand(10, 20, 3); newI = 3*I; for Ind=1:3; esta = linsolve(newI(:, :, Ind), I(:, :, Ind)); estI(:, :, Ind) = esta; end; figure;imshow(estI);
    • 能否请您澄清要求解的线性方程在哪里以及 esta = linsolve(newI(:, :, Ind), I(:, :, Ind)) 的含义是什么;
    • 是否可以将两个不同尺寸的图像相乘?例如 size(A)=512 256 3 和 size(B)= 256 512 3 给出 256 256 3 的 RGB 图像?我试过了,但错误是???使用 ==> mtimes 时出错整数只能与同一类的整数或标量双精度数组合。 ==> 在 17 处相乘时出错 aMat(:, :, Ind) = a(Ind)*eye( size(Img, 1), size(Img, 2) );
    • 它只需要im2double。我将imread 的输出提供给它。
    猜你喜欢
    • 2014-11-21
    • 1970-01-01
    • 2016-10-23
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多