【问题标题】:How to fix this error Index in position 2 exceeds array bounds in MATLAB?如何解决此错误 位置 2 中的索引超出了 MATLAB 中的数组边界?
【发布时间】:2021-03-15 19:55:03
【问题描述】:

这行代码bloop(rj,cj) = J1(i,j) 有问题。我尝试了很多并更改了数字,但错误仍然存​​在。 错误是 位置 2 的索引超出数组范围 bloop(rj,cj) = J1(i,j).

我希望有人能解决这个问题。

clc 
clear 
close all
J = imread('logo.jpg'); %discolored image
J1 = im2double(J); %convert image to bouble precise
[r,c] = size(J1); %find size of image
rc = r*c; %151874

%find A inverse
x = [17;121;171];
xT = x';
xxT = x*xT;
inv = pinv(xxT); %find inverse for singular or badly scaled
y = [17;122;114];
yxT = y*xT;
Ainv = yxT*inv;
B = Ainv;

%find color correction
%reshape matrix to 3xn
i = 0;
j = 0;
bloop=zeros(3,50625);
for rj = 1:3 %row
    i = i+1;
    for cj = 1:50625 %cols
        j = j+1;
        bloop(rj,cj) = J1(i,j);
    end
end
[w,t] = size(bloop);
bloop(:,:)
%I(r,c) = BJ(r,c)color correction equation
I = B*bloop; 

【问题讨论】:

  • 你的图片是 3x50625 吗?
  • 是的,它的 3x50625
  • 简单地使用reshape函数改变它的大小

标签: arrays matlab image-processing matrix reshape


【解决方案1】:

对于每个 rj/i,您的 j 不会被重置为零。在 i 循环内移动 j = 0

clc 
clear 
close all
J = imread('logo.jpg'); %discolored image
J1 = im2double(J); %convert image to bouble precise
[r,c] = size(J1); %find size of image
rc = r*c; %151874

%find A inverse
x = [17;121;171];
xT = x';
xxT = x*xT;
inv = pinv(xxT); %find inverse for singular or badly scaled
y = [17;122;114];
yxT = y*xT;
Ainv = yxT*inv;
B = Ainv;

%find color correction
%reshape matrix to 3xn
i = 0;
bloop=zeros(3,50625);
for rj = 1:3 %row
    i = i+1;
    j = 0; 
    for cj = 1:50625 %cols
        j = j + 1;
        bloop(rj,cj) = J1(i,j);
    end
end
[w,t] = size(bloop);
bloop(:,:)
%I(r,c) = BJ(r,c)color correction equation
I = B*bloop; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 2021-06-30
    相关资源
    最近更新 更多