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?
Emulating a resize algorithm
Re: Emulating a resize algorithm
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Emulating a resize algorithm
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
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/
https://imagemagick.org/Usage/