Saving segmented character sequentially (Matlab)

2 次查看(过去 30 天)
I have the code for word images segmentation into characters. The segmentation is running well. But I have to save all the result of segmented words (each character image as one file) sequentially. But this code just save the last segmented character in every word images. The code is as follow:
for z = 1: 300
name1 = strcat ('data (',int2str(z),').png');
name2 = strcat ('D:\1. Thesis FINISH!!!\source\', name1);
a = imread (name2);
myFolder = 'D:\1. Thesis FINISH!!!\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 = 0;
% threshold=min(verticalProjection)/3;
% threshold = 5; % Threshold >0 used for cursive characters
thresholdedProjection=verticalProjection > threshold;
count=0;
startingColumns = [];
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)];
y = 1;
% *Extract each region, result of segmentation process*
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));
baseFileName = sprintf('data.%d.png', y);
y=y+1;
% Prepend the folder to make the full file name.
fullFileName = fullfile(myFolder, baseFileName);
% Do the write to disk.
imwrite(t, fullFileName);
% imwrite (t, fullfile (myFolder, sprintf ('data.%d.png', y)));
% y = y+1;
end;
The saved file of segmented characters is supposed to be like this:
But the code doesn't work. Any help and explanation would be very appreciated.
Thank you
  2 个评论
yamina jafri
yamina jafri 2017-4-2
Hello @ana ain i try alot to do segmentation from word to character..but I did not succeed! can you please help me this is my email: yaminajafri@yahoo.com
Image Analyst
Image Analyst 2017-4-2
As of the original post, no solution had been found by her. You might want to ask someone else after you read this link.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by