Page 1 of 1

Emulating a resize algorithm

Posted: 2011-12-04T07:52:20-07:00
by Jason S
I worked out most of the details about how Photoshop resizes images (link). For no particular reason, I want to see if ImageMagick can be made to resize images in the same way. There are two things I still need:

1. A way to apply a box filter that also translates the image by a fraction of a pixel. I tried to do this with +distort, but couldn't make it work quite right.

2. A way to apply a blurry cubic filter in one dimension (which will be resized), but not in the other dimension (which will stay the same size).

Can these things be done?

Re: Emulating a resize algorithm

Posted: 2011-12-04T14:14:48-07:00
by Jason S
I figured out a way to make the box filter work. I'd assumed I could distort both dimensions at once, but it only works if I separate them.

Code: Select all

convert Rings1.gif \
  -filter box -define filter:blur=0.707 \
  +distort SRT "0,0 0.8,1.0 0 0.3999,0.0" -crop 800x1000+0+0 \
  +distort SRT "0,0 1.0,0.8 0 0.0,0.3999" -crop 800x800+0+0 \
  -transpose \
  -filter cubic -define filter:b=0 -define filter:c=2.2 -define filter:blur=1.05 \
  -resize 200x200 \
  -transpose \
  im-bicubicsharp.png

Re: Emulating a resize algorithm

Posted: 2011-12-04T19:05:28-07:00
by anthony
Photoshop will be using a two pass system just as you described. the IM -resize operator does this too.
But distort does it as a single 2 dimentional pass.

You can use a Affine distortion instead of SRT so you can resize the image based on control points rather than a scaling factor. The control points are floating point, and should be n image coordinates (center of top left pixel is at +0.5+0.5)

See IM examples Distort, Resize
http://www.imagemagick.org/Usage/distorts/#resize