no filter windowing when making an image smaller
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
no filter windowing when making an image smaller
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.)
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.)
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: no filter windowing when making an image smaller
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.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?
Fred
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: no filter windowing when making an image smaller
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: no filter windowing when making an image smaller
Aside. If people are agreeable I will move this discussion to the "Digital Image Processing" forum.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
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.)
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.)
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
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.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.
In any case, it appears that "box-windowed" Sinc/Jinc is something worth a second look.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
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
is a really good result. For example, it is much better, IMHO, than CORRECTION: NOT MUCH BETTER
(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!
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
Code: Select all
convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos \
-resize 800x500 \
lanczos.png
P.S. Once I've fixed the code, the difference is not as stunning. Hmmm!
Last edited by NicolasRobidoux on 2011-03-15T15:12:38-07:00, edited 12 times in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: no filter windowing when making an image smaller
out of curiosity, what is the difference between:
-define filter:filter=lanczos
and
-filter lanczos
-define filter:filter=lanczos
and
-filter lanczos
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
4 hours sleep.fmw42 wrote:out of curiosity, what is the difference between:
-define filter:filter=lanczos
and
-filter lanczos
Last edited by NicolasRobidoux on 2011-03-14T14:21:01-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: no filter windowing when making an image smaller
That is the life of a University professor trying to make tenure!4 hours sleep.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
Code: Select all
convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos2 \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos2_distort.png
------
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.
Last edited by NicolasRobidoux on 2011-03-15T08:21:53-07:00, edited 5 times in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: no filter windowing when making an image smaller
You can see what differences there are after all settings have been applied using -define filter:verbose=1fmw42 wrote:out of curiosity, what is the difference between:
-define filter:filter=lanczos
and
-filter lanczos
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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: no filter windowing when making an image smaller
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:
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:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
Anthony:
I agree that the "no windowing" is a dead horse for downsampling, at least if lobes > 2. See "CORRECTION" above.
I agree that the "no windowing" is a dead horse for downsampling, at least if lobes > 2. See "CORRECTION" above.
Last edited by NicolasRobidoux on 2011-03-15T15:17:51-07:00, edited 1 time in total.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: no filter windowing when making an image smaller
Code: Select all
convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos2 \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos2_distort.png
Code: Select all
convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
-filter lanczos2sharp \
+distort affine '0,0,0,0 %w,0 800,0' \
lanczos2sharp_distort.png
Code: Select all
convert 69543104.bHSz3aSK.Downsampletestimage.jpg \
+distort affine '0,0,0,0 %w,0 800,0' \
distort.png
Code: Select all
convert 69543104.bHSz3aSK.Downsampletestimage.jpg -filter mitchell -resize 800x500 mitchell.png
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
Last edited by NicolasRobidoux on 2011-03-16T04:15:02-07:00, edited 10 times in total.