I'm trying to convert images containing greyscale text on white background (improperly) saved as JPG into PNG, but that produces files larger than the original due to the JPEG artifacts (the text otherwise looks OK, i.e. the artifacts are mild).
Currently it looks like this (gamma exaggerated for illustration purposes):
If I convert it as-is, the size increases because of the JPEG artifacts.
Example:
Original JPEG: ipsum.jpg, 10KB
Converted to PNG: ipsum.png, 14KB
What's the best way to reduce the noise but without distorting the text? (I rather keep some noise than remove some detail from the text)
Removing JPEG artifacts from scanned text
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Removing JPEG artifacts from scanned text
It depends on the objective. As the linked images look okay, why do want to change them? Once an image has been saved as JPG, converting from that to almost any other format will increase the file size. This is because the image has been distorted in accordance with JPEG compression.
If you want to save space, then thresholding at 50% will result in very good PNG compression. But, of course, that's another distortion, which removes anti-aliasing.
This saves some space (mostly by converting many near-white pixels to exactly white) without doing much damage.
If you want to save space, then thresholding at 50% will result in very good PNG compression. But, of course, that's another distortion, which removes anti-aliasing.
Code: Select all
convert ipsum.jpg -level 5%,95% out.png
snibgo's IM pages: im.snibgo.com
Re: Removing JPEG artifacts from scanned text
Thanks for the suggestion but threshold loses too much detail.
So far I could come up with :
So far I could come up with :
Code: Select all
mogrify -despeckle -fuzz 5% -fill white -opaque white -gamma 0.8 -colorspace gray -depth 6 -format png *.jpg