Convert an image from grayscale to binary

12,140

Solution 1

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...

Solution 2

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.

Share:
12,140

Related videos on Youtube

Tim
Author by

Tim

Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.

Updated on September 17, 2022

Comments

  • Tim
    Tim over 1 year

    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!