extract characters from image
Asked Answered
C

5

6


Im trying to extract (not recognize!) characters from a black & white image,
so if the image is 123, i get an array of 3 images,

its a duplicate question, i know, but i couldnt find what i want, i also tried looking through codeproject but couldnt find a working example

http://www.codeproject.com/Articles/143059/Neural-Network-for-Recognition-of-Handwritten-Digi
source code not complete


your help is much appreciated :)

Condescension answered 18/2, 2012 at 15:4 Comment(2)
I'm pretty sure you're going to have to recognize the characters in order to extract them. OCR is the way to do this.Decasyllable
@M.Babcock: Not necessarily. You can identify the bounds of a digit’s representation within an image by following adjacent black pixels.Fyrd
G
5

As Kenny has already mentioned, "connected component labeling" describes a family of algorithms that identify connected pixels. Connected components also go by the name of "connected regions" or "blobs", and also by the related concept of "contours." Any such algorithm should be able to find not only a shape of connected foreground pixels, but also the presence of "holes" inside the shape consisting of pixels of the background color.

http://en.wikipedia.org/wiki/Connected-component_labeling

This algorithm is used for several engineering fields that rely on image processing, including computer vision, machine vision, and medical imaging. If you're going to spend any amount of time in image processing, you should become very comfortable with this algorithm and implement at least once on your own.

The OpenCV library has a findContours() function that can be used to find contours, contours within contours, etc.
http://opencv.willowgarage.com/wiki/

If you'd like to see a region-labeling algorithm at work, look for references to "cell counting" using the application ImageJ. Counting biological cells is an important and oft-cited application of region labeling for medical imaging.

http://rsbweb.nih.gov/ij/

Consider getting a textbook on the subject rather than learning piecemeal online. Studying connected components (a.k.a. blobs) inevitably leads to consideration of binarization (a.k.a. thresholding), which takes a grayscale or color image and generates a black and white image from it. If you're working with images from a camera, then lighting becomes critical, and that takes time and tinkering to learn.

There are a host of other preprocessing steps that may be necessary to clean up the image. The need for preprocessing depends on your application.

Here's a textbook that is often recommended, and that gives good coverage of standard image processing techniques:

Digital Image Processing by Gonzalez and Woods, 3rd edition http://www.imageprocessingplace.com/

Go to addall.com to find cheap copies. International editions are cheaper.

If the characters (or other shapes) in the image are of a consistent size and shape--for example, an "A" is always 40 pixels tall and 25 pixels and machine printed in the same font--then you might use a "normalized cross-correlation" or template-matching technique to identify the presence of one or more matching shapes. This technique can work as a very crude sort of OCR, but has severe limitations.

http://en.wikipedia.org/wiki/Template_matching

Grouty answered 18/2, 2012 at 16:7 Comment(0)
A
3

If your image represents black characters on a white background (or vice versa) and if the image is of reasonable quality and if the lines of text are horizontal and if each character is separated from its neighbours it is a relatively trivial operation to find all the little islands of black pixels in the sea of white.

As each of these ifs is relaxed the problem becomes harder but remains the same conceptually: find a black pixel then find all the other black pixels to which it is connected and you have found a character. Or, bearing in mind the comments about OCR and your requirement, you have found a patch of black pixels which (you assert) represent a character.

Angelynanger answered 18/2, 2012 at 15:19 Comment(2)
all these conditions are set, but im sure there's some library or something that does what i need, i think reading a book and researching papers (like Rethunk suggested) is a bit overkill :)Condescension
Lots of SO posts on this and similar topics recommend OpenCV. I see it has a function 'findContours' which might get you started.Angelynanger
W
1

I have put code up on code project which does exactly what you want.
Connected Component Labeling and Vectorization

Its a single pass contour extraction using the paper A Linear-Time Component-Labeling Algorithm Using Contour Tracing Technique by Fu Chang, Chun-Jen Chen, and Chi-Jen Lu.

Wolsey answered 15/7, 2012 at 14:7 Comment(0)
S
0

You may find it useful to learn about Blob or Connectivity Analysis in machine vision. Most libraries, including the free ones, have something like this. Also, if you know the orientation, text is b/w and the text is spaced nicely, you should be able to find the character edges in the 1d projection of the image in X and Y or any angle if you have the time.

Shenitashenk answered 18/2, 2012 at 15:31 Comment(0)
I
0

In my opinion, the best answer so far is by Rethunk as he points out that you should use segmentation and connected component labeling. HighPerformanceMark basically describes the connected component labeling algorithm (which is a very simple one), but I think that mentioning the name of the algorithm is important for this kind of answer.

Note however that segmentation and connnected component labeling is just the start point to solve your problem. For example, some letters, like lowercase 'i' will be composed by two components and you should consider that you may have ligatures (i.e. two letters that are connected to each other). That's why I like M. Babcock comment: it is hard to have a good solution to your problem without recognizing characters.

For your problem, I believe that you can solve your problem by using an OCR library.

Isomorphism answered 18/2, 2012 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.