Page 1 of 2

no filter windowing when making an image smaller

Posted: 2011-03-13T10:41:35-07:00
by NicolasRobidoux
Looking at things carefully, it would appear to me that there is no need to window filters when they are used to downsample (for example, to make an image smaller).

Actually, it looks to me that, as a general principle, windowing should only be used when upsampling (for example, when enlarging an image).

This suggests that, when downsampling, using truncated Sinc/Jinc/Lagrange may give better results than, say, Lanczos or Hamming or Jinc-windowed Jinc, at least when the truncation window is not too small.

Does anybody know references about this or have practical experience that would suggest that the above "don't window when downsampling" rule of thumb is right?

(Anthony? Fred?)

Pushing this one step further: Anybody knows whether this also applies when doing transformations that don't upsample much (e.g., rotating)?

(Part of why I'm curious is because it is standard to apply sharpening following downsampling, which suggests that blur is an important artifact when downsampling. Windowing, more or less, is a way of ensuring that the truncated Sinc/Jinc filter is smooth. If blur is the primary "bad," making the filter smooth is not important. If people have had good results with wide Lagrange filters, which are approximations of Sinc (without windowing), then this suggests that using un-windowed Sinc/Jinc when downsampling may be a good approach.)

Re: no filter windowing when making an image smaller

Posted: 2011-03-13T11:20:03-07:00
by fmw42
Does anybody know references about this or have practical experience that would suggest that the above "don't window when downsampling" rule of thumb is right?
I don't have enough experience with the windowing issue in downsampling to be able to respond. I suppose some experiments would be in order.

Fred

Re: no filter windowing when making an image smaller

Posted: 2011-03-13T20:20:18-07:00
by anthony
I have no idea.

My understanding is that windowing is used for two reasons.

1/ to limit the scope of IIR (Infinite Impulse Response) functions. For Gaussian a simple box or support factor is all that is used. Too small a support factor with gaussian causes a sudden 'step' in the filter where it gets cut off, leaving behind some aliasing. Before I redeveloped gaussian uses a support of 1.25 which produced quite a sever step. that was later expanded to 1.5 and later again expanded to 2.0 (for easier handling)

2/ to reduce the response of the filter to zero as it approaches the support factor. That was supposed to be particularly important to reduce ringing effects in Sinc filters, and produce a better frequency response.

There was certainly a lot of studies done to produce a 'good' windowing function, and looking at raw 'box windowed' sinc up-sampled results, definitely shows that it is a good thing.

However for Downsampling (which IM defaults to Lancosz, unless transparency is present) I can not be sure if it is needed or not. Some photoshop tutorials however seems to indicate that ringing can also be a problem in downsampling.

I never really claimed to be a true expert in filters. I only know what I have experimented with and looked at, which has given me a good understanding of them. I certainly don't know our understand frequency spectrum analysis which is heavily used for figuring out what is a good windowing function.

However I strongly doubt that using raw 'box windowed' sinc for down-sampling (image shrinking) is a good thing, especially for minor reductions in size where some interpolation filters still seem to work better. As for major large scale reductions, who knows raw sinc may be better, but then it is hard to tell in that case as so many pixels get merged together in big image reductions.

Re: no filter windowing when making an image smaller

Posted: 2011-03-13T20:21:43-07:00
by anthony
Aside. If people are agreeable I will move this discussion to the "Digital Image Processing" forum.

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T03:30:38-07:00
by NicolasRobidoux
My hunch is this:

When downsampling (at least sufficiently), windowing with a "smooth window" makes the image unnecessarily blurry, which is why the result is generally sharpened.

(Also: Don Munsil strongly warns against taking frequency response analysis too seriously when resampling.)

I'll put doing tests on my to do list. (Starting with box-windowed EWA (distort) Jinc2 and Jinc3.)

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T07:30:11-07:00
by NicolasRobidoux
anthony wrote:...
However I strongly doubt that using raw 'box windowed' sinc for down-sampling (image shrinking) is a good thing, especially for minor reductions in size where some interpolation filters still seem to work better. As for major large scale reductions, who knows raw sinc may be better, but then it is hard to tell in that case as so many pixels get merged together in big image reductions.
To make a long story short, if no windowing is better when downsampling a lot, you can blend a windowed version (e.g. Lanczos3) with an "un-windowed" one (e.g. Sinc3) with the blending weights depending on the amount of downsampling that's being done. If the downsampling was minor, the blend would be almost pure windowed filtering; if producing a thumbnail, the blend would be almost pure un-windowed filtering.

In any case, it appears that "box-windowed" Sinc/Jinc is something worth a second look.

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T14:05:01-07:00
by NicolasRobidoux
I'm not sure that no windowing is a good idea when downsampling, but EWA Jinc-Jinc distort does appear (again?) to be a good idea when downsampling.

Try this for yourself:

Dowload the test image from here: http://www.pbase.com/konascott/image/69543104/original
which I got following the following link: http://www.photography-forums.com/re-do ... 85435.html

I've not taken the time to align the results of distort and resize, but it appears that

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos_distort.png 
is a really good result. For example, it is much better, IMHO, than CORRECTION: NOT MUCH BETTER

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos \
-resize 800x500 \
lanczos.png
(Hopefully my test code is OK: running on little sleep.)

P.S. Once I've fixed the code, the difference is not as stunning. Hmmm!

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T14:07:53-07:00
by fmw42
out of curiosity, what is the difference between:

-define filter:filter=lanczos

and

-filter lanczos

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T14:14:10-07:00
by NicolasRobidoux
fmw42 wrote:out of curiosity, what is the difference between:

-define filter:filter=lanczos

and

-filter lanczos
4 hours sleep.

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T14:15:47-07:00
by fmw42
4 hours sleep.
That is the life of a University professor trying to make tenure!

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T14:34:19-07:00
by NicolasRobidoux

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos2 \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos2_distort.png
looks pretty good.

------

I was hoping for a smoking gun, but this is starting to look like the usual "devil in the details."

P.S.

I'll have to do a more careful comparison when I have a minute (for example, making sure to align the distort results with the resize results, and I'll have to compare to Mitchell), but the above still looks quite good to me compared to everything else. With (resize) Lanczos, one can see faint "bounceback" halos (the dark ring around the light ring). Of course, there is none of that with lanczos2.

P.S. 2

Thank you Anthony and Fred for pointing out my wonky syntax.

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T20:07:56-07:00
by anthony
fmw42 wrote:out of curiosity, what is the difference between:

-define filter:filter=lanczos

and

-filter lanczos
You can see what differences there are after all settings have been applied using -define filter:verbose=1

Seems to be no difference unless you also change some other aspect. Remember Lanczos is really a compound filter, not the underlying weighting and windowing functions.

For a boxed Jinc use -define filter:filter=jinc


Also I do recommend you specify the input image first!

Re: no filter windowing when making an image smaller

Posted: 2011-03-14T20:17:56-07:00
by anthony
The -filter lanczos downsample seems same between EWA distort and normal Resize

Using -define filter:filter=jinc instead (which produces a boxed jinc), seems a lot fuzzier overall, with some obvious ringing effects along the roof-sky edge, and some distinct wave patterns in the grass.

convert down-sample-test.jpg -filter lanczos +distort affine '0,0,0,0 %w,0 800,0' show:
vs
convert down-sample-test.jpg -define filter:filter=jinc +distort affine '0,0,0,0 %w,0 800,0' show:

Re: no filter windowing when making an image smaller

Posted: 2011-03-15T08:07:34-07:00
by NicolasRobidoux
Anthony:

I agree that the "no windowing" is a dead horse for downsampling, at least if lobes > 2. See "CORRECTION" above.

Re: no filter windowing when making an image smaller

Posted: 2011-03-15T08:32:13-07:00
by NicolasRobidoux

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos2 \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos2_distort.png
still looks really good to me. Compared to resize or distort lanczos (3 lobes), it has really mild haloing, and it does not have the "oversaturated" lanczos signature.

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos2sharp \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos2sharp_distort.png
also works well. So does dropping the "-filter ..." bit

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
+distort affine '0,0,0,0 %w,0 800,0' \
distort.png
(which results in the use of the Robidoux filter) which appears to have marginally less haloing yet is slightly sharper, and has a character fairly similar to Mitchell

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg -filter mitchell -resize 800x500 mitchell.png
except that is is slightly sharper.

The distort lanczoses have a slightly smoother halo compared to the resize ones (actually, they are a little smoother overall, which is not surprising; check the camper trailer). This is, however, a subtle thing, and I'll have to make sure the alignment is perfect between the resize and distort results before being conclusive.

-----

Also, distort sinc 2 lobes (unwindowed) seems to be OK for someone who values sharpness a lot. May remove the need to do a final upsharp mask? Here's the code:

Code: Select all

convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-define filter:filter=jinc \
-define filter:lobes=2 \
+distort affine '0,0,0,0 %w,0 800,0' \
sinc2_distort.png
Certainly not an all purpose downsampling method, but could be used, I guess, to get snappy thumbnails/very sharp looking smaller versions of an image without creating much moire. (Big time haloing is the price, but this may not be a bad thing, say, on the screen of an iPhone viewed outdoors.)