Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a bitonal image for OCR using Image Magick

nice /usr/local/bin/convert \
  -colors 2 \
  -colorspace gray \
  -compress group4 \
   /var/www/html/uploads/pokemon.jpg \
   /var/www/html/uploads/pokemontest.jpg

This command worked with a really OLD version of Image Magick.

With the newest version this method produces a completely black image.

nice /usr/local/bin/convert \
  -colorspace gray \
  -compress group4 \
   /var/www/html/uploads/pokemon.jpg \
   /var/www/html/uploads/pokemontest.jpg

nice /usr/local/bin/convert \
   -colors 2 \
    /var/www/html/uploads/pokemontest.jpg \
    /var/www/html/uploads/pokemontestfinal.jpg

This results in a bitonal gray and black image, but it's really rough. NOT clean at all.

like image 487
Greg Avatar asked Jun 27 '26 04:06

Greg


1 Answers

You could try a simple

convert  input.jpg  -threshold 50%  output.jpg

(and play a bit with variations of the 50% setting) and see if this gets you any further.

Also, you may want to have a look at these answers:

  • Image Preprocessing steps to improve the recognition rate
like image 166
Kurt Pfeifle Avatar answered Jun 29 '26 22:06

Kurt Pfeifle