0

I have some binary images with text, like below:

image 1:

enter image description here

image 2:

enter image description here

And the corresponding horizontal projection is:

projection for image 1: enter image description here

projection for image 2: enter image description here

It seems that I can segmentation by the horizontal projection, but how?

Thanks in advance!

PS: code to do the projection:

from matplotlib import pyplot as plt
import pylab

(rows,cols)=img.shape
h_projection = np.array([ x/255/rows for x in img.sum(axis=0)])
plt.plot(range(cols), h_projection.T)
pylab.savefig(outfile, bbox_inches='tight')
plt.clf()

And to remove misunderstanding, when I say horizontal projection, I mean a projection made on a plane parallel to the horizon.

Zieng
  • 453
  • 1
  • 7
  • 17
  • Use a threshold on the projection with a high value (e.g. 0.95). Then you have a 1D mask with _sequences_ of zeros (false) where you have letters and other stuff. and ones (true) where you have all white coulmns. The starting and ending indices of the true sequences tell you where the white columns start and end. See [here](http://stackoverflow.com/a/35014061/5008845) for an hint (in C++) – Miki Oct 28 '16 at 09:49
  • Thanks @Miki . I will try it later. I think the most prominent different between the text and other stuff is that the text area has rapidly changing value on the projection image, so I want to use this feature to find the text area. But unfortunately I don't know how. – Zieng Oct 28 '16 at 12:57

1 Answers1

-1

Segmentation can be done by using vertical projection followed by horizontal projection. But to discriminate the text letter from other unwanted stuff you can use shape based feature descriptors like 'Histogram of Oriented Gradients'. And using those features you can train SVM or neural network based classifiers, But for training first you need database(like MNIST) of those sample letters images.

Gaurav Pawar
  • 449
  • 2
  • 7
  • 1
    This should be a comment, as it doesn't answer the question – Miki Oct 28 '16 at 12:29
  • @Gaurav Pawar Thanks for your reply. The images are already the result after I apply vertical projection and some more analysis. The origin images are far more complicated. So I already cut the text in to a row, and now I need to find a way to remove unrelated stuff in this row and only keep the text. – Zieng Oct 28 '16 at 13:02