Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Reading in an image?

  1. Apr 27, 2007 #1
    Hey guys,

    I was wondering if anyone knows of an open source solution for reading in a black and white image and converting it to text (preferably in a text file)?

    I've tried Google, but I could only find online generators.

  2. jcsd
  3. Apr 27, 2007 #2
    Will Gimp do what you want?

    Otherwise, I have a vague recollection (+10 yrs ago) of using some command line utils in unix like png2pbm. No idea if that kind of stuff is still around.
  4. Apr 27, 2007 #3


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Some things that come up on a google search of: freeware ocr




    http://documents.cfar.umd.edu/ [Broken] (repository)
    http://www.adams1.com/pub/russadam/ocr.html [Broken]
    http://www.heatonresearch.com/articles/42/page1.html (project)
    http://www.codeproject.com/dotnet/simple_ocr.asp [Broken] (project)
    Last edited by a moderator: May 2, 2017
  5. Apr 27, 2007 #4


    User Avatar

    I've tried some of the opensource alternatives, and I must say was disapointed. :( I't might be some settings that needed to be done though. I gave up after a while
  6. Apr 28, 2007 #5
    Thank you for those links, but they are kind different from the type of manipulation I need.

    Aren't there any algorithms that just straight take in a black & white image and turn it into binary?
  7. Apr 28, 2007 #6


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    What is the format of the input image?
    Once the image is read in, it shouldn't be too hard to compete a short computer program in (say) perl, python, c, java...
  8. Apr 28, 2007 #7
    The images can either be PNG or TIFF files. If there is code that only works for one of the previously mentioned file types, that is fine.
  9. Apr 28, 2007 #8


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    If I had to quickly write something to do this, I would personally choose one of these apparoaches:

    write a program in Python using the Python Imaging Library http://www.pythonware.com/products/pil/

    write a program in Java using ImageJ and some selection from its plugins http://rsb.info.nih.gov/ij/ http://rsb.info.nih.gov/ij/plugins/index.html

    The above, however, would not be very portable... except to other computers with these installed.

    As I hinted above, the hardest part would be to read in the image file... probably best handled by someone else's routines that the rest of your program would call.
    Last edited by a moderator: Apr 22, 2017
  10. Apr 28, 2007 #9
    Converting an image to text can obviously not done with a short computer program. It is actually quite complex.

    - Oh, never mind, you were commenting on converting the image to a binary.

    What I am waiting for is for some student to write an OCR program that converts formulas into latex. Would be a nice project and would benefit many.
    Last edited: Apr 28, 2007
  11. Apr 28, 2007 #10


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    The OP is not looking for an OCR program... but a program which converts a 2-color image into some kind of text file with a binary or hexadecimal representation of the image.

    Did you see the InftyReader project in the links I posted above?
    Here are some samples: http://www.inftyproject.org/en/demo.html#0002
  12. Apr 28, 2007 #11
    I see sorry for the confusion.

    Heh, interesting! I am going to check it out!
  13. Apr 28, 2007 #12
    Exactly. This conversion from a 2 color image to text is only a small part of an overall project, so if I don't need to mess around with writing the program myself, and could perhaps use an open source solution, that would be fantastic.
  14. Apr 28, 2007 #13


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    The Python PIL and ImageJ solutions are open source platforms... But I doubt you will find an already written program that does what you want. (However, see below.) If this is part of a larger project, these solutions above might be worth looking into.

    Here is one question though... are you looking to create a text file comprised of only "0" and "1" corresponding to the 2 colors of an image? [Rather than (say) a text file with a hexadecimal representation, each line corresponding to eight rows of the image.] In other words, are you looking for something like [but not precisely] this: http://www.text-image.com/ or http://ascii.dyne.org/ ?
    Last edited by a moderator: Apr 22, 2017
  15. Apr 28, 2007 #14
    I'm not sure either really capture what I'm looking for, but if I had to choose one, I'd say the second link depicts what I'm trying to do better.

    For the first link, the images are converted to 1's and 0's, but it doesn't seem like those values represent anything.

    What I'm looking for is to take a black and white image in, and have the black areas represented by 1's and the white areas represented by 0's.
    Last edited by a moderator: Apr 22, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Reading in an image?
  1. Image Processing (Replies: 4)

  2. Read array (Replies: 4)

  3. Fortran read (Replies: 9)