Page 1 of 1
Converting to Monochrome
Posted: 2012-06-21T17:19:57-07:00
by stevenp
I have a need to use
gocr and to improve it's recognition I have to convert an image to Black & White.
the source image:
opened and saved as "Monochrome Bitmap" in Windows 7 x64 Paint
and gocr recognizes all the numbers from the image
then because I need this stuff working in an AutoHotkey script, I have tried ImageMagick
at first it was as simple as
but the result is:
then i tried another approach
Code: Select all
convert in.jpg -colors 2 -monochrome in.pcx
still not the result I pursued
I tried few hours to obtain the same result as in MS Paint but with no luck.
Neither of trials was recognized by gocr.
The most similar was to use contrast:
Code: Select all
convert in.jpg -contrast-stretch 700x0 -monochrome in.pcx
But the text gocr recognized:
Code: Select all
__o__?q__00__0___0______0__?0_____
Please Help, i have tried various dithering methods too with no luck
Maybe you have a better experience with ImageMagick and could reproduce the monochrome image from mspaint with ImageMagick.
Please
Re: Converting to Monochrome
Posted: 2012-06-21T18:24:18-07:00
by fmw42
try this and adjust the threshold percent as desired.
convert sourcem.png -colorspace gray -auto-level -threshold 50% result.pcx
Re: Converting to Monochrome
Posted: 2012-06-21T18:47:29-07:00
by stevenp
thanks it was really easy to deploy resultNN.pcx with a batch file and check results with another one
-colorspace gray -auto-level -threshold 50% result.pcx
the threshold 64% gived the near-identical result, but gocr still didn't recognized nothing, so it's probable a gocr fault or something wrong with the pcx files
Opened in Photoshop and... there's a difference
Re: Converting to Monochrome
Posted: 2012-06-21T18:49:28-07:00
by stevenp
However, there's everything fine when viewing in some viewer, like ACDSee:
it's because the image is still 24bit
I have tried -depth 2, but the pcx still remain at 24 bits per pixel
So now the question is how to save a 1-bit per pixel pcx file?
Thanks
Re: Converting to Monochrome
Posted: 2012-06-21T18:53:03-07:00
by anthony
stevenp wrote:thanks it was really easy to deploy resultNN.pcx with a batch file and check results with another one
-colorspace gray -auto-level -threshold 50% result.pcx
the threshold 64% gived the near-identical result, but gocr still didn't recognized nothing, so it's probable a gocr fault or something wrong with the pcx files
Opened in Photoshop and... there's a difference
That looks like a file file format error of some kind.
For other ways of thresholding see
http://www.imagemagick.org/Usage/quantize/#monochrome
You will not what dithering.
You could also try 'two color quantization' which is a sort of 'auto-level threshold'.
Just turn of dithering!
Re: Converting to Monochrome
Posted: 2012-06-21T18:54:17-07:00
by stevenp
it's because the image is still 24bit
I have tried -depth 2, but the pcx still remain at 24 bits per pixel
So now the question is how to save a 1-bit per pixel pcx file?
Thanks!
Re: Converting to Monochrome
Posted: 2012-06-21T19:13:31-07:00
by stevenp
Solved by saving as pgm file - it is supported in gocr
Thanks for the Help!
Re: Converting to Monochrome
Posted: 2012-06-21T19:15:57-07:00
by anthony
try -type grayscale
or -type bilevel
Re: Converting from Bitmap to 1Bpp image
Posted: 2015-05-07T23:53:55-07:00
by Thirumal
Can any one please share Code to convert Bitmap to 1Bpp image. Looking forward for your reply.
Re: Converting from Bitmap to 1Bpp image
Posted: 2015-05-08T09:53:39-07:00
by fmw42
Thirumal wrote:Can any one please share Code to convert Bitmap to 1Bpp image. Looking forward for your reply.
Please provide an example input image. You can upload to some place such as dropbox.com and post the URL here.
Also always provide your version of IM and platform.
Without seeing your image, we do not know if it is color or grayscale, but try
Code: Select all
convert image -colorspace gray +dither -colors 2 -type bilevel result
or
or
Code: Select all
convert image -colorspace gray -threshold XX% -type bilevel result