fmw42 wrote: ↑2018-02-17T16:03:13-07:00
The point is, if you create more colors than your input bit-depth and the output format supports it, you will get a higher bit depth result with more colors.
OK, but png certainly supports more than 1 bit of color, yet the result of the deskew operation on my file was a 2-color png, unless I explicitly set a higher depth. (I don't understand what png's reported depth of 8/1 bit means exactly.)
A bunch of results for the colors from identify:
Original pgm: 1-bit Bilevel Gray
info: output after deskew: 1-bit Gray
png output after deskew: 8/1-bit Gray 2c
tiff output after deskew: 1-bit Bilevel Gray
png output after deskew with depth set to 8: 8-bit Gray 256c
tiff output after deskew with depth set to 8: Grayscale Gray
The tiff and png with depth 8 are identical. The png and tiff without 8 bits are
not identical. The tiff looks has more black pixels, like the - output, though also not quite identical to it. I don't think I'd have noticed this issue if the png didn't look so different from the original.
Interestingly to me, if I use output and input to/from standard in/out, the depth seems to be ignored and the output png is 8-bit Gray 2c:
convert -deskew 40% -depth 8 test.pgm - | convert - line.png
However using a write to memory yields 8-bit Gray and an identical file to the depth 8 png/tiff:
convert -deskew 40% -depth 8 test.pgm -write mpr:test +delete mpr:test info:
Not setting depth yields 1-bit Gray, as with others.
So, what I see is:
1. Original file depth is preserved in output file, if that output offers the same depth. JPEG therefore gets 8-bit while png or tiff get 1, even though both png and tiff can handle >1 bit.
2. Explicitly setting depth results in output file with that depth and the grays actually used.
3. Writing to - does not preserve the depth even when explicitly set, even though in this case it doesn't calculate which pixels stay black in the same way that the png output does.
4. Writing to memory seems to work like writing to files.
It looks to me like the output file retains the depth setting of the input unless otherwise instructed or unless it can't (like jpeg). Setting depth keeps the new colors resulting (in this case) from the deskew. What I don't get is why using standard in/out seems to ignore the depth.
fmw42 wrote:I noticed the loss in quality between your original PGM and PNG. That may be due to the fact that PGM is linear gray, if I recall, and PNG assumes non-linear.
This doesn't happen without deskew, so a simple convert to png creates an identical image.