I am new in matlab and I am trying to write a code that can separate hand written numbers form a squared page background. I have tried using kmeans to differ the numbers from the lines and the squers , but it doesn’t work on all images . Any ideas how can I do it? Tahnks!
Asked
Active
Viewed 348 times
1
-
Could you show an example image + the result of your attempt (including the used code)? – Dennis Jaheruddin May 01 '13 at 11:52
-
Sure, here is a link to download the code : http://www.speedyshare.com/9KAK7/Untitled.m and a link to a "good" picture : http://www.speedyshare.com/X8c8T/1.jpeg and link to a "bad" picture : http://www.speedyshare.com/RCSaU/badpic.jpg – user2339198 May 01 '13 at 12:19
-
and here is a word document that shows the results : http://www.speedyshare.com/B3rkx/results.docx – user2339198 May 01 '13 at 12:26
-
Interesting project you have here. While there are many complex computer vision and image processing solutions to this problem, I think your solution so far is pretty good as far as simple implementations go. I think one technique to look at would be 2D fourier tranforms; the periodic grid lines in the background are a prime target for frequency filters. – Suedocode May 02 '13 at 00:10
-
ur links don't work anymore. Could you post workable links again? I'd like to have a loot at it. Thanks. – magarwal Oct 11 '13 at 13:35
1 Answers
2
I'm using the EBImage package in R, but I'm sure you can find the equivilent in matlab:
Starting with the original image:
# Read and extract greyscale image # Run kmeans with 3 centers km = kmeans(as.vector(x), 3) c = km$centers # 1 0.4936797 # 2 0.2841005 # 3 0.6456494 # Extract smallest cluster 2 (your numbers) as binary image t = (km$cluster==2) r = matrix(t, nrow(x))
r now looks like:
# Apply morphological opening (erode then dilate) with smallest possible structural element kern = makeBrush(3, 'box') #[,1] [,2] [,3] #[1,] 1 1 1 #[2,] 1 1 1 #[3,] 1 1 1 z = openingGreyScale(r, kern)
z now looks like

Omar Wagih
- 8,504
- 7
- 59
- 75