2

I was wondering how to convert an image from grayscale to binary. The image is a one-page document in pdf format.

If I use Imagemagick's convert 1.pdf 1.eps to convert it to eps or other formats such as tif, I find the image becomes blurry. How can I preserve the clarity of the image?

Thanks!

0

3 Answers 3

3

Hm, it seems like that image is stored into the PDF as a bunch of long small "strips" of the complete image. It also seems like there is a filter or set of filters applied in the PDF that makes the image to be shown as b/w instead of the graylevels that it really is. You can open it in Inkscape, for example, to see some of this for yourself, as it seems like these filters aren't imported (I guess the same happened when you converted to PS or TIFF).

Turning it from a grayscale to a bitmap will probably require a bit of playing with contrast & such to get an optimal result (the scan isn't very hi-res to start with...).

You can import the PDF into The GIMP and play with various filters and colour-options, or maybe use similar functions in imagemagick to create a bitmap version. It's difficult what filter/setting will give the best results...

1

Open in the gimp, import pdf at 300dpi, go image > mode > indexed, and select 1 bit (black/white), save as tiff with no compression. Once you have a tiff that is essentially the image as a raster format in binary, and you can open in a raster processing program / image library of your favourite language or convert it to an ascii grid using gdal_translate

I'm fairly sure with imagemagick if you specify -density 300 it'll be the same effect as using gimp at 300dpi if you needed to do batch conversions. Your eps/pdf viewer is rasterising the vector source to your displays resolution at its zoom level, i.e. at 200% on a 75dpi screen the effective dpi for a rasterisation that your viewer is doing is 150 and so on, so pick the zoomlevel you want the image to look clear at for processing etc and then set your conversion tools dpi accordingly.

0

-monochrome

This option uses some smart dithering and generates very visible output:

convert -monochrome in.png out.png

Documentation: http://www.imagemagick.org/Usage/quantize/#monochrome

Compare that to a simpler -threshold 50 transform:

convert -threshold 50 in.png out.png

which loses most of the image.

Concrete example from: https://www.nasa.gov/mission_pages/galex/pia15416.html

wget -O orig.jpg http://www.nasa.gov/images/content/650137main_pia15416b-43_full.jpg
# Downsize to 400 height to have a reasonable file size for upload here.
convert orig.jpg -resize x400 in.jpg
convert -monochrome in.jpg out.jpg
convert -threshold 50 in.jpg threshold-50.jpg

in.jpg

enter image description here

out.jpg

enter image description here

threshold-50.jpg

enter image description here

Related questions:

Tested in Ubuntu 19.10, ImageMagick 6.9.10.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.