2016-08-01 1 views
-1

세분화 프로세스를 위해 코드를 수정했습니다. 그러나 "인덱스가 행렬 치수를 초과합니다"오류가 발생합니다. 코드는 다음과 같습니다.세분화 프로세스 (Matlab)에서 "인덱스가 행렬 차원을 초과합니다"를 해결하는 방법

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

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

을 변경하려고했습니다하지만 여전히 작동하지 않았다. 나는이 코드가 무엇이 잘못되었는지 전혀 모른다. 누구든지 설명하고 도와 줄 수 있습니까?

+0

오류가 발생한 라인은 어디입니까? – Salman

+0

안녕하세요 트로이, || 색인이 행렬 크기를 초과합니다. || 세그먼트의 오류 (줄 64) || subImage = i (:, startingColumns (k) : endingColumns (k)); –

답변

1
당신이 startingColumns 아닌 것 같아 코드에서 라인 (64)에 endingColumns(k)k을 변경할 수 있습니다

endingColumns 같은 수의 요소를 가지고있다.

+0

네, 그렇다고 생각합니다. 그것이 도움이되지 않는 이유입니다. || 그러면 오류를 해결하기 위해 코드에서 무엇을 변경해야한다고 생각합니까? –

+1

'k'는'startingColumns'의'end'를 초과해서는 안됩니다. 그런 조건을 추가해보십시오. – Salman

+0

'endingColumns = [startingColumns (2 : end) -1 j-floor (count/2)];'startingColumns와 동일한 요소 수를가집니다. 사실이 아닌가? 'endingColumns'는 (2 : end)와'endingColumns (end) = j-floor (count/2) '를 가지고 있기 때문에'endingColumns'는 (1 : end-1)과 같은 값을가집니다. 그래서 요소의 수가 동일하지 않습니까? –

관련 문제