How to solve "Index exceeds matrix dimensions" error in segmentation process (matlab)
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have segmentation code as follows. I've tried to segment all 300 word images, into characters images using vertical projection method. But I get "Index exceeds matrix dimensions" error, for k.
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;
Because I thought it's about the dimension, so i've tried to exchange
subImage = i(:, startingColumns(k):endingColumns(k));
become
subImage = i(startingColumns(k):endingColumns(k),:);
But nothing change. I have no Idea, what's wrong, which part I should modified to get it segmented correctly?
Any help and explanation would be very appreciated. Thank You so much.
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!