Gradient masks - is it possible?
Gradient masks - is it possible?
I know Imagemagick supports 'variable blur mapping' which lets you supply an image + gradient, and the image is blurred using the gradient as a mask to determine blur intensity. I've looked through as much documentation as I could but can't seem to find a way to use a 'variable mapping' procedure for transforms other than blurring.
I am curious if it is possible to use a gradient as a mask for the built-in distortion transformations.. such as the pincushion 'barrel' distortion, but only in a specified region with variable intensity, like the example below:
original image:
gradient mask:
desired result:
This is something that could be done with ease in Photoshop--selecting the center region with the elliptical marquee tool, and then 'feathering' the selection by 15px or so, and applying the distortion. (Or even doing it exactly as above using a gradient as a layer mask, like the example above.)
Simply cropping out the region of interest, distorting it, then replacing it back into the original image in the same spot doesn't work, because of issues with alpha blending on the edges (im using an image that has transparency in it). Any advice would be much appreciated.
I am curious if it is possible to use a gradient as a mask for the built-in distortion transformations.. such as the pincushion 'barrel' distortion, but only in a specified region with variable intensity, like the example below:
original image:
gradient mask:
desired result:
This is something that could be done with ease in Photoshop--selecting the center region with the elliptical marquee tool, and then 'feathering' the selection by 15px or so, and applying the distortion. (Or even doing it exactly as above using a gradient as a layer mask, like the example above.)
Simply cropping out the region of interest, distorting it, then replacing it back into the original image in the same spot doesn't work, because of issues with alpha blending on the edges (im using an image that has transparency in it). Any advice would be much appreciated.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Gradient masks - is it possible?
I would do this with absolute distortion maps.
1. Create an identity distortion map.
2. Distort this map in whatever way you want.
Now you have two distortion maps. If you applied (1) to your image, it wouldn't change. If you applied (2), the entire image would be distorted.
3. From those, create a third distortion map, using your gradient as a mask:
Then use map3.png as your distortion map.
1. Create an identity distortion map.
2. Distort this map in whatever way you want.
Now you have two distortion maps. If you applied (1) to your image, it wouldn't change. If you applied (2), the entire image would be distorted.
3. From those, create a third distortion map, using your gradient as a mask:
Code: Select all
convert map1.png map2.png grad.png -composite map3.png
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Gradient masks - is it possible?
Naming your first two images inGrid.png and inMask.png, and using a heavy barrel distortion for clarity, Windows BAT syntax:
Code: Select all
set IDENT=^
0,0,#008,^
%%[fx:w-1],0,#f08,^
0,%%[fx:h-1],#0f8,^
%%[fx:w-1],%%[fx:h-1],#ff8
%IM%convert ^
inGrid.png ^
( +clone ^
( +clone ^
-sparse-color bilinear "%IDENT%" ^
) ^
( +clone ^
-distort Barrel 0,0,-0.5 ^
) ^
-delete 0 ^
inMask.png ^
-compose Over -composite ^
) ^
-compose distort -composite ^
outMaskedBarrel.png
snibgo's IM pages: im.snibgo.com
Re: Gradient masks - is it possible?
snibgo, thanks for your suggestions - I should have actually uploaded the PNG of the grid I was using rather than taking a screenshot (the grid has a transparent background) so using the batch script produces an ghost image underneath.. e.g.
Using masks in photoshop definitely provides 'variable' intensities of the distortion effect in relation to how much the mask tells it to, which is why I was hopeful Imagemagick might have something comparable considering it has that variable blur mapping. I was confused by your original answer - sorry.
Using masks in photoshop definitely provides 'variable' intensities of the distortion effect in relation to how much the mask tells it to, which is why I was hopeful Imagemagick might have something comparable considering it has that variable blur mapping. I was confused by your original answer - sorry.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Gradient masks - is it possible?
So, please upload the grid and gradient you actually want to use. (My script should work with them.)
snibgo's IM pages: im.snibgo.com
Re: Gradient masks - is it possible?
Here is the grid & mask.
http://doir.ir/inGrid.png
http://doir.ir/inMask.png
I processed the images above through the batch script, and the image I posted a moment ago was the result.
http://doir.ir/inGrid.png
http://doir.ir/inMask.png
I processed the images above through the batch script, and the image I posted a moment ago was the result.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Gradient masks - is it possible?
The problem is that your grid is in the alpha channel and the underlying image is totally black. Put the alpha channel into the underlying image first and see if that works.
Code: Select all
convert inGrid.png -background white -alpha background inGrid2.png
Re: Gradient masks - is it possible?
Just attempted to run the above command - but the inGrid2.png output seemed to be the same thing as the input (inGrid.png).. no? at any rate - I tried to run the batch file again with inGrid2.png as the input and it produced that same ghost image I posted above.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Gradient masks - is it possible?
As Fred says, it is the alpha channel that needs to be distorted. (The colour isn't entirely black, but a very dark weird pattern. Never mind.)
This makes a grayscale image of the alpha. Put that through the code I gave above. Then CopyOpacity to put the result as the alpha channel in the original image, or on an entirely black image.
Or, if you want the weird almost-black pattern distorted, then distort that as well as the alpha channel.
Code: Select all
%IM%convert ^
inGrid.png ^
-alpha extract ^
p.png
Or, if you want the weird almost-black pattern distorted, then distort that as well as the alpha channel.
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Gradient masks - is it possible?
Or we can do the whole job in a single convert:
(%IDENT% is as above, using a variable purely for convenience.)
This uses an opaque image to create a distortion map, then uses the map to distort both colours and alpha together.
Code: Select all
%IM%convert ^
inGrid2.png ^
( +clone ^
-alpha opaque ^
( +clone ^
-sparse-color bilinear "%IDENT%" ^
) ^
( +clone ^
-distort Barrel 0,0,-0.5 ^
) ^
-delete 0 ^
inMask2.png ^
-alpha off ^
-compose Over -composite ^
) ^
-compose distort -composite ^
ingrid_out2.png
This uses an opaque image to create a distortion map, then uses the map to distort both colours and alpha together.
snibgo's IM pages: im.snibgo.com
Re: Gradient masks - is it possible?
man this is great - this works beautifully! Thank you very much for the help. Now I've gotta dissect and figure out exactly what's goin on in this batch script exactly . Thanks again.