Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binarize an image

Cropped Image 1

Cropped Image 2

Binarized Image

I am sorry for image sizes.

Now these two cropped images I have in a dataset. I am going to feed these images into a machine learning algorithm. Before doing that, I want to extract binarized digits and feed the binary images into algorithm, instead of feeding directly. Can you please elaborate how can I achieve this kind of clean binarization ?

I found otsu and other thresholding methods but they were unable to give clear digits in image.

like image 794
user3206070 Avatar asked Aug 16 '26 17:08

user3206070


1 Answers

I had some success, though I don't know how it will fare with the rest of your images, using a 2-colour quantisation, conversion to greyscale and normalisation.

I just did it at the command line with ImageMagick, as follows:

convert input.png +dither -colors 3 -colors 2 -colorspace gray -normalize -scale 250x result.png

So, it loads an image and disables dithering, so that the subsequent quantisation only results in 2 actual colours rather than dithered mixtures. I then quantise down to 3 colours - still in RGB colourspace - and then further down to 2 colours. Then, I convert those 2 colours to greyscale and normalise them so the darker one becomes black and the lighter one becomes white.

enter image description here

enter image description here

like image 174
Mark Setchell Avatar answered Aug 19 '26 08:08

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!