non-linear scaling

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
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

non-linear scaling

Post by josephs »

Hi all.

I would like to apply a non-linear scaling to an image with image edge as center point.

To illustrate what I am trying to achieve, I have manually created an input and output file in Photoshop. I have used a a grid to help visualize, but the effect will be applied to photos. Basically, the stretching should progressively increase from top of image to bottom of image. There should be no virtual pixels because the bottom and top edge remain fixed.

https://drive.google.com/file/d/16C_w5_ ... sp=sharing
https://drive.google.com/file/d/1YDsvVO ... sp=sharing

Thus far I have been going the route of displacement maps using simple gradient but that squeezes the image from both ends - not in one direction. If any one could lead me in the right direction it would be appreciated.

Thanks.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: non-linear scaling

Post by GeeMack »

josephs wrote: 2018-12-21T17:40:28-07:00Thus far I have been going the route of displacement maps using simple gradient but that squeezes the image from both ends - not in one direction. If any one could lead me in the right direction it would be appreciated.
There was a discussion on that issue just a couple months ago. You may find some helpful pointers at THIS link. Several methods are described, and there's a link to one of Fred's scripts which should accomplish the task.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: non-linear scaling

Post by snibgo »

josephs wrote:...displacement maps using simple gradient but that squeezes the image from both ends - not in one direction
Perhaps you used "-compose Displace", which is for relative displacement maps, not absolute displacement maps.

This seems very close (identical?) to what you want:

Code: Select all

%IMG7%magick ^
  checks.png ^
  ( +clone ^
    -sparse-color Bilinear ^
0,0,#008,^
%%[fx:w-1],0,#f08,^
0,%%[fx:h-1],#0f8,^
%%[fx:w-1],%%[fx:h-1],#ff8 ^
  -channel G -evaluate Pow 0.5 +channel ^
  ) ^
  -compose Distort -composite ^
  out.png
It creates an identity absolute distortion map, then distorts the green channel, which controls vertical movement. We can use any function. We need a function that maps 0=>0, 1=>1 and 0.5=>about 0.7.
snibgo's IM pages: im.snibgo.com
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: non-linear scaling

Post by josephs »

Yes. Exactly what I was looking for. Thanks for your help! I was nowhere close to this.
Post Reply