A Minimal Image to Text Converter in Python (for binary images)

Posted: June 5, 2010 in Image Processing, Python

Here is a minimal image image to text converter using python imaging library, PIL. The program receives its input a binary BITMAP(.bmp) image, (i.e it  has only pixel values (0,0,0) and (255,255,255) . Jpeg files do not produce a perfect output, may be because of the encoding used. The converter program scans the whole image and creates a set of values which are written to a text file “text”. The equivalent text can be seen in the output file.

An example of a text generated from a bitmap image is shown below:-

The Binary image of a square

00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000111111111100000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000

The source code of the program is :-

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s