|
Tuesday, July 22, 2008 |
Activity 10: Preprocessing Handwritten Text |
Continuing the challenge of real life image processing problems we were tasked to label handwritten texts. We were given 2 scanned documents:
Interpreting the instruction "Crop a portion of the image... with text within the lines." I "selectively, selected" the numbers written within the document on the right since these do not overlap with the lines (making my work easier, hehehe). The results are shown below:
As can be seen, applying the right filter can eliminate the hard horizontal lines to appear as smudges instead. The next step is to binarize the image and label the results. But as we would notice below, binarizing would yield black handwritten text (black is background!). Therefore, inversion of the image was performed after which the morphological tools of opening and closing were done. Having completed these procedures we can now label safely:
As can be seen from the results, the numbers: 7,6,8 are not only recognizable to us but also to the computer (in the context that it, was labeled as 1 character hehehe). The other two characters were butchered in the process however... although it is right that the two should be recognized as having two characters each, its just that the 10 and twelve both look like mangled 11s.
The code I implemented was my own:
clear all; chdir('G:\poy\poy backup\physics\186\paper 10');
im = gray_imread('4piece.jpg'); scf(0); subplot(1,3,1) imshow(im); fim = fftshift(fft2(im)); fim(1:23,55:57) =0; fim(29:51,55:57) =0; //filter shape F = real((fim).*conj(fim)); fim1 = log(F+1); subplot(1,3,2) imshow(fim1,[]);// shows the fourier transform xset('colormap',jetcolormap(255)); new = abs(fft2(fim)); subplot(1,3,3) imshow(new,[]);// shows the new image
Im = im2bw(new, 110/255) // set the right contrast scf(1); subplot(2,2,1) imshow(Im); Im = 1*(Im==0); // inverts the values subplot(2,2,1) imshow(Im);
se = ones(2,1); Im = erode(Im,se); Im = dilate(Im,se); //open Im = dilate(Im,se); Im = erode(Im,se); //close subplot(2,2,3) imshow(Im);
[L,n] = bwlabel(Im); subplot(2,2,4) imshow(L+1,rand(n+1,3)); //shows the labeling
And since I felt bad after I've "selectively selected" what I wanted to process I performed the same procedure for a different "selectively selected" portion of the first image on the left, the results are shown below:
Unlike the first I've processed, these had characters coinciding with the hard horizontal lines (albeit only a few)and like earlier, the lines were removed to be changed to smudges. Performing the next procedure to see if a good labeling can be done we can observe that From the word "Extension cord", using a (2x1) rectangular structuring element, the word "cord" can be labeled and distinguished, I also chose the same structuring element since the letter "S" from the first word is very evident albeit connected with the mangled "extension"
I enjoyed this activity! I performed everything on my own recalling my experience from previous activities! I give myself 10/10 neutrinos!
|
posted by poy @ 11:26 PM |
|
1 Comments: |
-
WoW ! This is good!
Indeed, sometimes the way the images are sampled (in your case, cropped) can spell the difference between success and failure. I totally liked the first sample. The second sample was not bad either. You correctly chose an appropriate structural element.
|
|
<< Home |
|
|
|
|
|
|
WoW ! This is good!
Indeed, sometimes the way the images are sampled (in your case, cropped) can spell the difference between success and failure. I totally liked the first sample. The second sample was not bad either. You correctly chose an appropriate structural element.