Wednesday, July 23, 2008

A11 - Preprocessing Handwritten Text







First, we get chose a portion of the grayscaled image. Then we, removed the vertical lines by knocking-out the frequencies in the Fourier transform of the image that correspond to vertical lines. These are those frequencies that lie along the vertical axis of the shifted FFT. So the mask used was a black vertical strip with a hole in the middle so as not to remove the DC component of the image.





















Next, I binarized the image. I used thresholds = 80, 90 and 100 intensity values and found out that threshold = 80 is the best. So I, tried applying the operations closing of holes and opening of holes for the image and also opening the holes for holes-closed image. I think that the image became cleaner after performing closing of holes only. Next, I thinned the characters/regions into one pixel. The final image is shown in figure 6. While not all letters are recognizable, the letters U,P and S have been, in my opinion, enhanced.
















Enjoy mag-label ng continuous regions.
Code:
//1 Calls the image and converts it to grayscale
M = imread('D:\ap186\july20_2008\toEnhance3.jpg');
M = im2gray(M);
M = M-min(min(M));
M = 255*M/max(max(M));

//3 Shows the FFT of the best binarized image,K2
FM = fft2(M);
FMshift = fftshift(abs(FM));
//4 Creation of a mask to filter the horizontal and vertical lines in the image
[m,n] = size(M);mask = ones(m,n);
mask(:,n/2-5:n/2+5) = 0;mask(m/2-3:m/2+3,n/2-3:n/2+3) = 1;

//5 Shows the image FFT and the mask to be used
subplot(121)
imshow(log(FMshift),[]);
subplot(122)
imshow(mask);

//6 Filtering of the lines; the new image is called H
FHM = FM.*fftshift(mask);
H = abs(ifft(FHM));

//7 Shows the original image, the filtered image, and the latter's FFT
subplot(131)
imshow(M,[]);
subplot(132)
imshow(H,[]);
subplot(133);
imshow(fftshift(abs(FHM)),[]);
H = H-min(min(H));
H = 255*H/max(max(H));
subplot(221)
histplot([0:255],H);
subplot(222)
L1 = im2bw(H,90/255);
L1 = 1-abs(L1);
imshow(L1);
subplot(223);
L2 = im2bw(H,100/255);
L2 = 1-abs(L2);
imshow(L2);
subplot(224);
L3 = im2bw(H,110/255);
L3 = 1-abs(L3);
imshow(L3);

//Close or Open holes for L1
L = ones(2,2);
zero = zeros(2,2);
negL = abs(zero-L);
D = dilate(L1,negL);
Close = erode(D,negL);
E = erode(Close,L);
Open = dilate(E,L);

subplot(221)
imshow(L2);
subplot(222)
imshow(Close);
subplot(223)
imshow(Open);
subplot(224)
thn = thin(Close);
imshow(thn);
lbl = bwlabel(thn);
imshow(lbl,jetcolormap(max(max(lbl))));
Grade: 8/10
processed image is not so readable

No comments: