Resizing a Gray TIFF file - conversion to linear colorspace required?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
datro
Posts: 15
Joined: 2018-01-16T19:26:03-07:00
Authentication code: 1152
Location: Washington D.C. area

Resizing a Gray TIFF file - conversion to linear colorspace required?

Post by datro »

New IM user and first post.
IM 7.0.7-19 Q16 x64 on a Windows 10 64-bit machine

I'm building a Windows batch script to handle downsizing of high resolution B&W TIFF files (originally produced on my drum scanner). The source files are TIFF, 16-bit, in Gray Gamma 2.2 colorspace. Output files will have the same attributes: TIFF, 16-bit, in Gray Gamma 2.2 colorspace (no change from input).

Here's an example of how I am currently doing the resize:

magick -quiet "filename.tif" -filter Quadratic -distort Resize 10800 -set density 720x720 "filename_720.tif"

This downsizes to a new width of 10800 pixels (height calculated by IM) and sets a new resolution of 720ppi into the output image. This command works fine, producing a new TIFF file with the desired 16-bit depth and Gray Gamma 2.2 colorspace ( as verified with "magick identify").

In Photoshop, a comparison of the source and output files shows image tonal values appear to have been extremely well preserved (though I will need to add some small amount of sharpening). However, I'm wondering whether I should be converting to a linear colorspace before doing the resize, then convert back. For color images (multi-channel) it's clear this is recommended. But for grayscale TIFF files, is it also recommended to do the colorspace conversion? What am I giving up if I don't do the conversion?

Assuming I should do the conversion, which of these would be better:

magick -quiet "filename.tif" -filter Quadratic -gamma 0.454545 -distort Resize 10800 -gamma 2.2 . . .
or
magick -quiet "filename.tif" -filter Quadratic -colorspace LinearGray -distort Resize 10800 -colorspace Gray . . .

Thanks,
Dave
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing a Gray TIFF file - conversion to linear colorspace required?

Post by snibgo »

To be technically correct, you should resize in linear colorspace. Does it make any difference? I doubt it. The difference will show only where you have very high frequency data (ie rapidly changing pixels).

I haven't tried the new "-colorspace LinearGray" yet, but that's probably the correct way. Doing it with gamma will be only very slightly wrong.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing a Gray TIFF file - conversion to linear colorspace required?

Post by snibgo »

You mentioned the need to sharpen after downsizing. That should have triggered me to mention the work by Nicolas Robidoux and others, which does both operations together, by blending a linear resize with one with a further shift of gamma 3. The results are excellent.

See Resampling with halo minimization, and the links from there.
snibgo's IM pages: im.snibgo.com
Post Reply