Direct resampling vs zero order hold + convolution

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Direct resampling vs zero order hold + convolution

Post by BryantMoore »

original
https://dl.dropbox.com/u/106615031/dsp/ ... e2/new.png
zero order hold
https://dl.dropbox.com/u/106615031/dsp/ ... zoh10x.png
direct resampling
https://dl.dropbox.com/u/106615031/dsp/ ... ize10x.png
zoh + convolution
https://dl.dropbox.com/u/106615031/dsp/ ... lur10x.png

The last two images both use an orthogonal triangle filter. What are the implications of this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Direct resampling vs zero order hold + convolution

Post by fmw42 »

a triangle filter does a linear interpolation in x and in y between pixels in the input image to find the correct color to assign to each output pixel based upon the scale factor.

There is much on this and more discussed at:

http://www.imagemagick.org/Usage/resize/#filter
http://www.imagemagick.org/Usage/distorts/#summary
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Direct resampling vs zero order hold + convolution

Post by BryantMoore »

I guess what I should ask is if the direct resampling or the convolution is a more accurate representation of how the final image should look.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Direct resampling vs zero order hold + convolution

Post by fmw42 »

sumawo13 wrote:I guess what I should ask is if the direct resampling or the convolution is a more accurate representation of how the final image should look.
You will have to tell us what the resampling filter is and what the convolution kernel is?

In general, resampling filters are nearestneighbor, bilinear (triangle), cubic convolution, lanczos, etc as described in the reference I provided. Whereas, convolution is just a blurring of the resulting enlargement. Typically a good resampling filter will beat a blurring convolution.

On the other hand, for example, photoshop does a bilinear or cubic convolutoin resampling followed by a hidden unsharp (misnomer) sharpening convolution. In this case there has been quite some discussion on the forum recently and tests by Professor Nicolas Robidoux suggesting that a properly designed filter can do as well or better than the photoshop process. See http://www.imagemagick.org/Usage/resize/#nicolas

"Adjusting the blur (between about 0.7 and 1.0) or B parameters (between 0.0 and 1.0) should obviate any need for USM (Unsharp) Sharpening. You may also want to try sigmoidizing."
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Direct resampling vs zero order hold + convolution

Post by BryantMoore »

fmw42 wrote:You will have to tell us what the resampling filter is and what the convolution kernel is?

In general, resampling filters are nearestneighbor, bilinear (triangle), cubic convolution, lanczos, etc as described in the reference I provided. Whereas, convolution is just a blurring of the resulting enlargement. Typically a good resampling filter will beat a blurring convolution.
Image

Code: Select all

$ convert rose: -sample 2000% +repage -define filter:verbose=1 -define filter:blur=20 -filter triangle -resize 100% 00-rose-blur-triangle.png
# Resize Filter (for graphing)
#
# filter = Triangle
# window = Box
# support = 1
# window-support = 1
# scale-blur = 20
# practical-support = 20
Image

Code: Select all

$ convert rose: -define filter:verbose=1 -filter triangle -resize 2000% 00-rose-resize-triangle.png
# Resize Filter (for graphing)
#
# filter = Triangle
# window = Box
# support = 1
# window-support = 1
# scale-blur = 1
# practical-support = 1
And as far as my version.

Code: Select all

$ identify
Version: ImageMagick 7.0.0-0 2012-09-29 Q32 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP  HDRI
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Direct resampling vs zero order hold + convolution

Post by BryantMoore »

Image

Code: Select all

$ convert rose: -sample 2000% +repage -define filter:verbose=1 -define filter:blur=20 -filter mitchell -resize 100% 00-rose-blur-mitchell.png
# Resize Filter (for graphing)
#
# filter = Cubic
# window = Box
# support = 2
# window-support = 2
# scale-blur = 20
# practical-support = 40
# B,C = 0.333333,0.333333
EWA Jinc Lanczos
Image

It seems to have a similar edge case with less ripple.
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Direct resampling vs zero order hold + convolution

Post by BryantMoore »

Code: Select all

$ magick rose: -sample 2000% -define filter:verbose=1 -define filter:blur=20 -filter lanczos -resize 100% rose-lanczos.png
# Resize Filter (for graphing)
#
# filter = SincFast
# window = SincFast
# support = 3
# window-support = 3
# scale-blur = 20
# practical-support = 60
Gives similar results to EWA Jinc Lanczos.

Image

It seems to be more "true" to the original image.
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Direct resampling vs zero order hold + convolution

Post by BryantMoore »

rose-blur-box.png (1400×920)
http://ompldr.org/vZnBhMw/rose-blur-box.png

rose-blur-triangle.png (1400×920)
http://ompldr.org/vZnBhNA/rose-blur-triangle.png

rose-blur-mitchell.png (1400×920)
http://ompldr.org/vZnBhNQ/rose-blur-mitchell.png

rose-blur-catrom.png (1400×920)
http://ompldr.org/vZnBhNg/rose-blur-catrom.png

rose-blur-lanczos.png (1400×920)
http://ompldr.org/vZnBhNw/rose-blur-lanczos.png

Code: Select all

#!/bin/sh
for f in box triangle mitchell catrom lanczos;
do
	magick rose: -colorspace rgb +sigmoidal-contrast 8 -sample 2000% -define filter:blur=20 -filter $f -resize 100% -sigmoidal-contrast 8 -colorspace srgb rose-blur-"$f".png
done
It seems with convolution, the box filter creates an effect similar to direct resampling with a triangular filter.
Post Reply