Page 5 of 5

Re: Correct resize

Posted: 2011-03-31T11:49:10-07:00
by NicolasRobidoux
Now for a nice theoretical surprise:

EWA triangle (that is, Clamped Elliptical Weighted Averaging resampling with the bilinear filter kernel) should be a decent scheme in any situation for which downsamling is occuring "all around" (that is, no resizing by making one dimension smaller and the other larger).

And it will be fast.

Re: Correct resize

Posted: 2011-03-31T17:07:07-07:00
by anthony
NicolasRobidoux wrote:No matter how much I like it, I'm not sure rose is the very best test image for enlargements because it appears that this thumnail was produced with some sharpening or most likely a ringing scheme (I'd guess (tensor) Lanczos 3 lobes).
The rose: image is a reduction of another image which you can get from
http://www.imagemagick.org/Usage/img_ph ... e_orig.png
This I recieved from Cristy, but I do not know if this was the original or where he got it from. It has been around as long a IM has.

I just happen to like using it for examples as it is the only 'photo' built-in image. I mean other than mostly bitmap 'patterns' you really only have a choice of rose: logo: netscape: granite:

Hold we now have a new addition -- wizard:
Though it seems to have a little too much white space for my liking. Would have been better off in portrait orientation too.
I'll submit that to Cristy.

Re: Correct resize

Posted: 2011-03-31T17:22:02-07:00
by anthony
NicolasRobidoux wrote:Now for a nice theoretical surprise:

EWA triangle (that is, Clamped Elliptical Weighted Averaging resampling with the bilinear filter kernel) should be a decent scheme in any situation for which downsamling is occuring "all around" (that is, no resizing by making one dimension smaller and the other larger).

And it will be fast.
While the filter is triangle, it isn't really bilinear, which is purely orthogonal use of the triangle filter. An EWA Triangle is more of a 'Cone' Filter. See table at the bottom of...
http://www.imagemagick.org/Usage/resize ... terpolated

Actually I think Hermite may be better!

I would like to see Hermite implemented as a fast, direct, unscaled point lookup, interpolation filter too.
Same with Catrom. The current 'Bicubic' interpolation filter is actually a Lagrange-3 cubic filter.
The very old bi-cubic interpolator 'Spline' is actually based on the B-Spline filter.

I probably should create a table of equivalences between Unscaled Interpolators vs Interpolated Resize Filters.

Perhaps I should actually move the whole 'interpolation' examples to just before Resize Filters. Or even split Filters as a separate page to resize. Great another ToDo! (don't mind me -- I'm just mumbling out loud!)

Re: Correct resize

Posted: 2011-03-31T17:36:54-07:00
by NicolasRobidoux
anthony wrote:...
Actually I think Hermite may be better!
...
I gathered this from some previous "thinking out louds."

I agree that Hermite may be better when, for example, enlarging in one direction and shrinking in the other.

However, I suspect that resize or distort triangle will be less aliased (less moire, in particular) than Hermite when "downsampling all around." But I may be wrong.

Re: Correct resize

Posted: 2011-03-31T18:55:09-07:00
by anthony
For upsampling hermite, and triangle is probably good.

ASIDE: A Resized upscale produce the same as there equivelent interpolations as the resize filter becomes 'unscaled'.

For downsampling a Sinc filter works better.

I have not compared Resize Sinc-based filters against Distort Jinc-based filters for downsampling.
Only the upsampling test with the rose which clearly shows the removal of 'jaggies' (block artifacts)

Re: Correct resize

Posted: 2011-04-01T04:48:12-07:00
by NicolasRobidoux
anthony wrote:For upsampling hermite, and triangle is probably good.

ASIDE: A Resized upscale produce the same as there equivelent interpolations as the resize filter becomes 'unscaled'.

For downsampling a Sinc filter works better.

I have not compared Resize Sinc-based filters against Distort Jinc-based filters for downsampling.
Only the upsampling test with the rose which clearly shows the removal of 'jaggies' (block artifacts)
I have compared Jinc VS Sinc for downsampling, and the preliminary results are that Jinc is (slightly) better.

So you know what I'm after w.r.t. using filters without negative lobes for downsampling:

I have a nonlinear ("adaptive") scheme, named Nohalo, which is good for upsampling and which, as the name indicate, does not produce any ringing. It is better than Hermite, for example. Nohalo is already implemented in VIPS/NIP2; also in a GEGL branch, in an outdated prototype version (I need to crack the whip on one of my grad students ;-))

For GEGL and VIPS/NIP2 ("competitors" of ImageMagick, kind of), I want to blend Nohalo with a scheme good for downsampling, with blending weights that depend on the transformation being applied (locally: when warping or doing perspective, one can switch from upsampling to downsampling within the same image).

So: I agree that a windowed Sinc (Jinc) is better when downsampling in general, but there are situations (certain types of art, for example: think old-style serigraphs or Matisse scissor art; apparently, some scientific-medical situations as well) in which ringing is a no-no. I'm hoping to set up Nohalo with the chosen downsampler as the preferred option in such situations. For this to be the case across the board I need to figure out what the best downsampling scheme with no (or almost no) ringing is.

At this point, my hunch is that it's going to be resize or distort triangle, quadratic or cubic (not Hermite), possibly but probably not with some blur < 1, or some version of Gaussian blur.

I'll keep you posted on what I find, and will read your comments with interest.

Re: Correct resize

Posted: 2012-03-28T19:18:25-07:00
by anthony
A year has passed, and I though I better add an update to this discssion, as it is being referenced from IM examples.

In ImageMagick version 6.7.5 the colorspace handling was changed (rather than waiting for IMv7)

Images are now assumed to be in sRGB (as per web conventions) when created or read in, and -colorspace RGB converts the time to linear-RGB. however when images are save both sRGB or RGB will save the image as is JPEG and PNG image file formats (no automatic conversion).

NOTE: converting to CMYK also now removes the non-linear component from sRGB colorspace.

Because of the resizing images using corrected colorspace now requires the colorspace arguments to be swaped.
As such this is now the way to do colorspace correction...

Code: Select all

   convert   image.png  -colorspace RGB  -resize 50%  -colorspace sRGB  image_half.png
See IM Examples, Resize with Colorspace Correction.
http://www.imagemagick.org/Usage/resize ... colorspace

Note Gamma correction remains unchanged!

Re: Correct resize

Posted: 2012-03-30T06:03:38-07:00
by NicolasRobidoux
When TIFF 16 bit three channel is read (and there is no embedded profile), is it assumed to be sRGB?

Same when there is a profile but import is not used?

Re: Correct resize

Posted: 2012-03-30T07:19:37-07:00
by magick
All images are assumed sRGB unless the metadata says otherwise (e.g. gamma 1.0 or embedded profile). We could assume that only 8-bit images are sRGB but its difficult to justify since almost all devices (cameras, LCD, etc.) have adopted the sRGB standard. You can override this assumption, by specifying otherwise on the command-line (e.g. -set colorspace RGB for linear RGB).