Wednesday, July 23, 2008

Activity10: Preprocessing Handwritten Text

In this activity, we were asked to use different image processing techniques to extract handwritten texts from an imaged document with lines.



To start with the activity, the following image was downloaded and a portion of it was cropped. This image will be processed such that the horizontal lines will be removed from the image and only the handwritten text will remain.

After applying fftshift to the image the resulting FT image is,


Then, after processing the image, the resulting image shows that the horizontal lines were removed as shown below.



The image was then binarized to clean the image of any unneeded pixels. The binarized image was also applied with opening operation using a 2x2 structuring element and the resulting image is shown below. Compared with the original image shown at the left, most of the horizontal lines were removed but the image texts were not reconstructed clear enough.



The code used for this activity is:

chdir('G:\186\activity10');
cropim = gray_imread('cropim2.jpg');
a1 = fftshift(fft2(cropim));
imshow(abs(a1), []);

[x,y]=size(a1);
a2=a1(:,:);
filter=ones(i,j);
for n=j/2-2:j/2+2
for m=1:i/2-2
filter(m,n)=0;
end
for m=i/2+ 2 : i
filter(m,n)=0;
end
end
a2=filter.*a1;
imshow(abs(a2), []);

fftim=abs(fft2(a2));
imshow(fftim, []);

grayim = gray_imread('fftim.bmp');
grayim = 1-grayim;
imbin = im2bw(grayim,0.5);
imshow(imbin);

square = ones(2,2);
im=erode(imbin,square );
im=dilate(im,square );
im=erode(im,square );
im=dilate(im,square );
imfinal=im;
imshow(imfinal);
[L,n] = bwlabel(imfinal);

rating-8, because the resulting image is not clear.
Acknowledgements: Jeric and Angel for helping me with the removal of horizontal lines.

1 comment:

Jing said...

Hi Julie,

A 2x2 square structuring element may not be the best one to use for this application. You may need to design your own, for example, a vertical line could be your strel, say a 3x1 pattern.