Summary: | Impossible to turn off dithering when converting to monochrome | ||
---|---|---|---|
Product: | Ghostscript | Reporter: | Adam Lesser <alesser> |
Component: | Color | Assignee: | Michael Vrhel <michael.vrhel> |
Status: | RESOLVED WORKSFORME | ||
Severity: | normal | CC: | dominic, marcin.zacharczuk |
Priority: | P4 | ||
Version: | master | ||
Hardware: | All | ||
OS: | All | ||
Customer: | Word Size: | --- |
Description
Adam Lesser
2013-11-07 13:24:40 UTC
It turns out you can do this if you know the right commands.. false bug report! (In reply to Adam Lesser from comment #1) > It turns out you can do this if you know the right commands.. false bug > report! Dear Adam, Can you or someone else share "right command" I did a LOT of research and testing in this area to find a solution that works for me. I still think GS could make this a lot easier than the "hack" I had to come up with below.. Hopefully this analysis I wrote on the topic helps. For others with this issue: I recommend playing around with the options below, but I found the combination of techniques in my last method (hybrid2) the best for myneeds. We have several options on how to fix the grayscale conversion problem. I will explain them in order, since they're a little fancy: • First, the method I call BNDither. This is an improvement on the dithering function by using a better dithering array (via the -Ilib stocht.ps option) that produces more visually pleasing output vs the default dithering function. This output basically results in better dithering, but doesn't turn it off. Command: /gs -q -dSAFER -dNOPAUSE -dBATCH -dUseCropBox -sOutputFile=BNDither300_%d.tif -r300 -dDITHER=300 -sDEVICE=tiffg4 -Ilib stocht.ps $FILE • Second, the method I call Threshold, uses a simple 50% threshold to determine if a pixel will be black or white. Dithering is turned off completely. Command: gs -q -dSAFER -dNOPAUSE -dBATCH -dUseCropBox -sOutputFile=Threshold_0.5_%d.tif -r300 -sDEVICE=tiffg4 -c "{ .5 gt { 1 } { 0 } ifelse} settransfer" -f $FILE • Third, a Hybrid method, that uses the above, improved dithering for everything below 50% threshold, and makes everything above 50% pure black. Command: gs -q -dSAFER -dNOPAUSE -dBATCH -dUseCropBox -sOutputFile=HYBRID_%d.tif -r300 -dDITHER=300 -sDEVICE=tiffg4 -Ilib stocht.ps -c "{ dup .5 lt { pop 0 } if } settransfer" -f $FILE • Fourth (best?) method called Hybrid2, improves on #3 above by adding the condition that anything "whiter" than the 70% threshold gets set to white, so that only things between 50-70% get dithered. This has the positive effect of removing a lot of page noise dithering on pages that don't scan perfectly white. It also removes annoying lite-colored backgrounds on color/gray images. Command: gs -q -dSAFER -dNOPAUSE -dBATCH -dUseCropBox -sOutputFile=HYBRID2_%d.tif -r300 -dDITHER=300 -sDEVICE=tiffg4 -Ilib stocht.ps -c "{ dup .5 lt { pop 0 } if dup .7 gt { pop 1 } if } settransfer" -f $FILE Adam has described the solution adequately, and this isn't really a bug in the first place since gs is doing exactly what it is supposed to, and we are not about to change the "default" settings to please a particular usage since that would probably break things for millions of others. Thanks to Adam for his work. BTW, many Artifex commercial customers have been provided with similar custom solutions in the past -- that's part of what supported customers get. Just wanted to say thanks @Adam Lesser for great tip: I have incorporated your Hybrid2 into my pdf-compress.sh script. Only difference that I use pngmonod output, but it works the same. |