Results 1 to 4 of 4
  1. #1
    morghul is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default Turning an image to binary

    hello,
    What i need is to turn an image of handwritten digits written with dark colour on a light background. I need to have white background and black digits, so I can prepare a vector for neural network.
    How should I do that? What algorithms should I use?
    Thanks

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    i would guess a good start would be to 'poster-ize' the image sample, that is to reduce its color depth

    I remember something from my academic years where scanning each pixel and observe the color of the adjacent pixels and if the majority of them are darker then this pixel becomes black and if the majority are lighter, this one becomes white. have a look at the "GIMP" (a desktop application,but they have some fun transforms such as this posterize feature.

    another thing to consider today, is how much granularity do we want to quantize the image in. back in the day when digital cameras only had a resolution of about 100 to 300 pixels, it was straight forward to create a recursive algorithm, or even a bunch of for() loops to scan each pixel in the image and it would work within a reasonable amount of time. Now that the cameras of today have thousands of pixels by thousands of pixels, the amount of processing time required to transform an entire image pixel by pixel can become quite huge.

    One approach is to create a 'software pixel', where you block the image out in groups of pixels, say 4x4 . and take an average value of all the pixels to mean the value of the one pixel. Now for hand writing this might need some playing with to find what the good amount of grouping pixels is with the resolution of your input digital image, but the the coarser the quantized input data is into the neural network, the easier it is to start working with it right, and the less chance of it intepreting small hand writing artifacts as parts of the characters.

    Now, for specific code or algorithms, I don't have any for these yet, but hoping these high level concepts are a good place to start for ideas.

  3. #3
    morghul is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Thanks for answer.

    What I do at the moment is:
    1. change the image colors to grey scale
    2.check pixel by pixel if it's darker then neighbours (to set frames around digits)
    3.cut each digit
    4.check each pixel if it's lighter than average of 10 pixels taken form the image.
    If it is then change it's colour to white, else change it to black

    It doesn't work slow, but the problem is when I have a high resolusion photo with noise then my algorithm fails.

  4. #4
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    hmm, that removal of noise from the image is a bit out of my expertise.

    There seems to be a lot of work in this field, certainly no shortage of patents

    Like this page:
    Keith Price Bibliography Noise Removal, Impulse Noise

    some of them even older.

    My thoughts, based on your current approach to average out pixels, what if you supplied a second step of averaging again after the first step, where you apply a weighting to the dark pixels based on how many continuous adjacent ones are. the theory being that smaller isolated spots might be the noise, and not part of a continous pen stroke that is part of a character.

Similar Threads

  1. Image to Binary bits
    By Deva in forum New To Java
    Replies: 4
    Last Post: 12-24-2009, 04:49 PM
  2. Code for image to binary
    By Deva in forum New To Java
    Replies: 3
    Last Post: 12-24-2009, 04:48 PM
  3. How save Image BMP Binary type?
    By shakall in forum SWT / JFace
    Replies: 3
    Last Post: 12-22-2009, 01:50 PM
  4. How to set the background of binary image?
    By hyz_zsu in forum Java 2D
    Replies: 1
    Last Post: 04-09-2009, 03:14 AM
  5. converting image to binary code n vice versa
    By nupurashi in forum Advanced Java
    Replies: 4
    Last Post: 04-01-2009, 07:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •