Effacer les filtres
Effacer les filtres

How to set dynamic threshold for segmentation purpose (MATLAB)

3 vues (au cours des 30 derniers jours)
ana ain
ana ain le 11 Août 2016
I need to segment 300 hundred word images, contain cursive characters. I've already try a segmentation code, using vertical projection method. It's good for isolated character, but not really work for cursive character.
But, finally we could segment the cursive character based on it's baseline. Using histogram that represent the profile of image, we could define the threshold to segment the image based on its baseline. My recent code, is as follows.
%%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; for isolated 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);
n =1;
Sample images:
My problem is, the threshold of all image are vary, different each other (although there are several have the same threshold). That's why I think, I need a dynamic threshold, but what I've tried, still didn't work. Any help and suggestion would be very appreciated.
Thank you so much.

Réponses (1)

Image Analyst
Image Analyst le 12 Août 2016
Just copy what someone else already invented and published. No need for you to reinvent the wheel. Find their algorithms here: http://www.visionbib.com/bibliography/contentschar.html#OCR,%20Document%20Analysis%20and%20Character%20Recognition%20Systems

Community Treasure Hunt

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

Start Hunting!

Translated by