Emulating a resize algorithm

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Emulating a resize algorithm

Post 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?
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Emulating a resize algorithm

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Emulating a resize algorithm

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply