How do you binarize a colored image?

What you want is referred to as "threshold" in image processing. Basically, it takes an image as an input and outputs an image that has all pixels with a value below a given threshold set to black, and all pixels the value of which is above the threshold set to white. This results in a black-and-white image from an arbitrary input image.

Generally, you want to convert to grayscale first for more predictable results, but it is possible to threshold a full-color image as well.

You can use a graphical tool such as GIMP to do this interactively (you'll find the tool through the main menu -> Colors -> Threshold), or you can use ImageMagick something like this:

convert colored.png -threshold 75% thres_colored.png

Running the above command on the example image produces the result shown below.

Black-and-white version of OP's image

Since thresholding is often somewhat of a trial-and-error process to get a result you're happy with, particularly if the source image is not very close to black-and-white already, I recommend the GUI approach if possible, but if that is not an option for whatever reason you can do it through the command line as well. For finer control of the output, you can use tools like color curves, levels and contrast first to isolate the light and dark portions of the image better before thresholding. (Actually, threshold can be seen as an extreme case of using the color curves tool.)


You can use Imagemagick:

convert test.png -colorspace Gray gray_colorspace.png

From here.

Here is what I got after applying to your image:

enter image description here


-monochrome from ImageMagick is an option that uses some smart dithering, and makes the output much more visible than -threshold if you intend it for human consumption:

convert -monochrome signature.png out.png

enter image description here

Does not make much difference for such a simple image, but for larger ones, it is striking:

  • https://stackoverflow.com/questions/15861025/how-to-convert-an-image-to-1bit-px-binary-bitmap-with-imagemagick-or-rmagick
  • https://askubuntu.com/questions/9868/convert-an-image-from-grayscale-to-binary
  • https://superuser.com/questions/405686/how-to-convert-a-photo-to-a-black-and-white-image-by-imagemagick
  • https://superuser.com/questions/75373/convert-color-photos-of-documents-to-good-black-and-white-bitonal-images

Tags:

Images