I am doing a project on offline handwriting recognition.In the preprocessing stage,I need to normalize the handwritten part in binary image w.r.t its size and position.Can anyone tell me how to access just the writing part(black pixels) in the image and resize and shift its position?
-
Could you be more specific about what you are asking? Your question is a bit unclear. The bottom of this page gives a clue on what to do: http://yann.lecun.com/exdb/mnist/. What else is in the image apart from writing. Have you segmented individual characters? – Bull May 24 '13 at 05:40
-
The standard handwritten samples against which we are comparing will have a particular size and the letters will be at some particular position of the page.So,before comparison between these two,the letters in the input samples should be converted to this size and placed in the same position,ryt?how to do that in matlab? – abc2013 May 24 '13 at 11:59
-
Is a hand written standard sample a single letter, a word, a line of text, or whole paragraph. Do we know the bounding box of every etter in the stand samples? "before comparison between these two" : which two? you have only mentioned the tandard samples so far. What is the format of th einput samples? What does "ryt" mean? – Bull May 24 '13 at 12:05
-
The standard samples and the input samples are single words.The input samples are binary images.The size of the words in the input has to be normalized to that of the standard samples.Also the word in the input binary image has to be positioned in the same location as the word in the standard sample is positioned. – abc2013 May 24 '13 at 13:16
-
My doubt is how to normalize the size and position of a word in a binary image in matlab according to some predetermined size and position? – abc2013 May 24 '13 at 13:18
1 Answers
Your problem is as broad as the field of image processing. There is no one way to segment an image into foreground and background so whatever solution you find here works on some cases and doesn't in others. However, the most basic way to segment a grayscale image is:
% invert your grayscale so text is white and background is black
gray_im = 1 - im2double(gray_im);
% compute the best global threshold
level = graythresh(gray_im);
% convert grayscale image to black and white based on best threshold
bw_im = im2bw(gray_im, level);
% find connected regions in the foreground
CC = bwconncomp(bw_im);
% if necessary, get the properties of those connected regions for further analysis
S = regionsprops(CC);
Note: Many people have much more sophisticated methods to segment and this is by no means the best way of doing it.
After post-processing, you will end up with one (or more) image containing only a single character. To resize to a specific size M x N, use:
resized_bw = imresize(single_char_im, [M N]);
To shift its position, the easiest way I know is to use circshift()
function:
shifted_bw = circshift(resized_bw, [shift_pixels_up_down, shift_pixels_left_right]);
Note: circshift
wraps the shifted columns or rows so if your bounding box is too tight, the best method is to pad your image, and re-crop it at the new location.

- 2,472
- 20
- 26
-
+1 for being clear on the general difficulty, yet providing an option – Schorsch Jun 21 '13 at 14:10