Last active
March 15, 2024 05:58
-
-
Save thomashollier/05dae38d09332c9ce0fdbd67d70356fd to your computer and use it in GitHub Desktop.
Imagemagick image warp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### Reference commands to do uv mapping with magick | |
| # create a grad by making 'n' vertical bands of colors and blurring | |
| echo "P2 4 1 255\n 137 195 125 255" | convert - -depth 16 -scale 151x50\! -blur 0x6 -resize 4096x1436\! +matte displace_map.tif | |
| # use the grad to warp image | |
| # note use of fx expression to make it resolution independent | |
| inputImage=test.jpg | |
| outputImage=testWarped.jpg | |
| magick ${inputImage} -depth 16 displace_map.tif -virtual-pixel Gray -compose Displace -set option:compose:args '%[fx:w*.0855]x%[fx:0]' -composite -crop '%[fx:h*2]x%[fx:h]+%[fx:w*0.146]+%[fx:0]' ${inputImage} | |
| ################################# | |
| # alternate means to make a arbitrary grad but it's a pain to setup and is not quite as directly controllable | |
| # Use this script to generate polynomial coefficients | |
| crv=$(./im_fx_curves -c -p 0,50 50,100 100,51) | |
| # Imagemagick command to apply them | |
| magick -size 512x512 -define gradient:direction=east gradient:black-white -function Polynomial "${crv}" poo.png | |
| ################################# | |
| ## Diplacement encodes how far to move the image pixel from its current location. Below 127 is left and above 127 is right | |
| magick {image} {displacement_map} \ | |
| -compose Displace -define compose:args={X}x{Y} \ | |
| -composite {result+} | |
| magick {image} {displacement_map} \ | |
| -compose Displace -set option:compose:args {X}x{Y} \ | |
| -composite {result+} | |
| magick composite {displacement_map} {image} \ | |
| -displace {X}x{Y} {result+} | |
| ## Distortion maps encode an absolute destination location for the pixel | |
| ## | |
| magick koala.gif map_compress.gif map_compress_y.gif \ | |
| -set option:compose:args '%[fx:w/2]x%[fx:h/2]' \ | |
| -compose Distort -composite \ | |
| distort_compose_set.gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment