如何解决;索引超出了矩阵维度“;在分割过程中(Matlab)

如何解决;索引超出了矩阵维度“;在分割过程中(Matlab),matlab,matrix,save,image-segmentation,Matlab,Matrix,Save,Image Segmentation,我已经修改了分段过程的代码。但是我得到了一个“索引超过矩阵维数”的错误。代码如下 for z = 1: 300 name1 = strcat ('data (',int2str(z),').png'); name2 = strcat ('D:\1. Thesis FINISH!!!\Data set\0 Isolated Dataset\Advertising Bold 14\source\', name1); a = imread (name2); myFolder

我已经修改了分段过程的代码。但是我得到了一个“索引超过矩阵维数”的错误。代码如下

for z = 1: 300
    name1 = strcat ('data (',int2str(z),').png');
    name2 = strcat ('D:\1. Thesis FINISH!!!\Data set\0 Isolated Dataset\Advertising Bold 14\source\', name1);

    a = imread (name2);

myFolder = 'D:\1. Thesis FINISH!!!\Data set\0 Segmented Character\coba';
%% Binarization %%
level = graythresh (a);
b = im2bw (a, level);

%% Complement %%
c = imcomplement (b);

%% PadArray %%
i=padarray(c,[0 10]);

%% Vertical Projecttion for Character Segmentation
verticalProjection = sum(i, 1);
set(gcf, 'Name', 'Segmentation Trial', 'NumberTitle', 'Off') 
subplot(2,2,1);imshow(i); 
subplot(2,2,3);
plot(verticalProjection, 'b-');
grid on;

% *Defining the threshold to determine baseline area* % 
threshold=max(verticalProjection)/3;
% threshold=min(verticalProjection)/3;
% threshold = 5; % Threshold >0 used to detect the baseline of cursive characters 
thresholdedProjection=verticalProjection > threshold;
count=0;
startingColumnsIndex=0;
for j =1:length(thresholdedProjection)
    if thresholdedProjection(j)
        if(count>0)
            startingColumnsIndex=startingColumnsIndex+1;
            startingColumns(startingColumnsIndex)= j-floor(count/2);
            count=0;
        end
    else
        count=count+1;
    end
end
endingColumns=[startingColumns(2:end)-1 j-floor(count/2)];

% *Extract each region, result of segmentation process* %
y=1;

for k = 1 : length(startingColumns)
    % Get sub image of just one character
    subImage = i(:, startingColumns(k):endingColumns(k)); 
    % im = subImage;
    s = subImage;

    % Normalization using algorithm 2 %
    p = normalization2 (s);

    subplot(2,2,2); 
    imagesc (p); 
    axis equal off;
    pause (1); 
%   figure, 
    imshow (p);

    % Morphological Operation - Thinning %
    t = bwmorph(p,'thin',Inf);  
end

% savename = char (strcat (myFolder, name1));
imwrite (t, fullfile (myFolder, sprintf ('data.%d.png', y)));
y = y+1;
end;  
我有300字的图像数据,我需要将所有图像数据分割成字符图像,并将它们保存为每个分割字符的不同文件。我需要按顺序保存它

我已经试着改变了

subImage = i(:, startingColumns(k):endingColumns(k)); 


但它仍然不起作用。我不知道代码出了什么问题。任何人都可以解释和帮助吗?

您可能需要更改第64行
结束列(k)
中的
k
。从代码中看,似乎
开始列
的元素数与
结束列
的元素数不一样,您在哪一行得到错误?嗨,特洛伊,|索引超过了矩阵维数。|分段T(第64行)| |子图像=i(:,起始列(k):结束列(k))中出错;是的,我想是的。这就是为什么它没有帮助的原因那么,您认为我应该在代码中更改什么来解决错误呢?
k
不应该超过
startingColumns
end
。尝试添加这样的条件。
endingColumns=[startingColumns(2:end)-1j-floor(count/2)]它的元素数与
起始列
相同。这不是真的吗<代码>结束列
的起始值(1:end-1)与
开始列
的起始值(2:end)和
结束列(end)=j-floor(count/2)
相同。元素的数量不是一样吗?是吗?在这个模拟中,我在工作区检查endingColumns value=[30,42,58,76,62]| |而startingColumns value=[7,31,43,59,77,64],它没有给出相同数量的元素。我已经得到了答案,分段已经运行良好。我只添加startingColumns=[];初始化起始列。||我想和大家分享一下,以防有人遇到同样的问题谢谢大家。。。
subImage = i( startingColumns(k):endingColumns(k),:);