Tilt Shift
Posted: 2013-06-29T13:24:35-07:00
Hi guys,
I am trying to produce a tilt-shift effect in ImageMagick via the command line but I am having some problems.
My set up:
ImageMagick-6.7.6-1 (Windows) This is a custom build with FFT compiled in, downloaded from here.
Ultimately I will be exec()'ing this from PHP, but it essentially a command-line issue.
The resources:
The Attempt
Running this command
(exclamation quoted for Windows escaping) give this result:
Superficially it looks very similar to the version created in Photoshop, certainly it could do with a little tweaking, for example the central section of the image is a little blurry, but I'm sure with some fiddling it would be OK.
Certainly I am reasonably happy with this result, but...
The Problem
It is very slow. I mean horribly slow. On my laptop this took roughly 60 seconds to create, Photoshop managed it in a few seconds. It gets worse for larger images since the strength of the blur has to be increased as the size of the image increases. I would be more than willing to sacrifice some quality of the blur if I could make reasonable gains in speed.
Attempted solution
After a lot of digging I stumbled across a method using an FFT to perform a blurring effect on this page, under the section "Blurring An Image - Low Pass Filtering".
This provides the following example:
To produce a blurry version of the original image. I downloaded the source image for the example and ran the code on my own machine and my output matched the example perfectly.
So, in order to re-produce the result with my example source image I replaced the image used in the above example with my "street.jpg", fixed the dimensions and tried to produce a blurred image with the following code:
The output from this is a blank black image.
I have been fiddling with the above example for quite a while, sometimes I manage to produce an image with some faint lines on it, or sometimes even a heavily distorted version of the original, but never something resembling a blur.
The Question(s)
I am trying to produce a tilt-shift effect in ImageMagick via the command line but I am having some problems.
My set up:
ImageMagick-6.7.6-1 (Windows) This is a custom build with FFT compiled in, downloaded from here.
Ultimately I will be exec()'ing this from PHP, but it essentially a command-line issue.
The resources:
- Source Image: (800x571)
- The mask: (800x600) I would like to resize the mask to match the source image, in this example it is very close in size.
- The expected result (done in Photoshop): I actually used a lens blur for this image and I understand that a gaussian blur will look different. The important thing to notice is that the image is blurred at the top and the bottom corresponding with the mask image. I think it is important that the mask determines the strength of the blur; whiter pixels in the mask means a larger blur radius.
The Attempt
Running this command
Code: Select all
convert.exe street.jpg ( tiltShift.png -gravity center -resize 800x571"!" -filter quadratic -compose blur -set option:compose:args 11 ) -composite -quality 90% test1.jpg
Superficially it looks very similar to the version created in Photoshop, certainly it could do with a little tweaking, for example the central section of the image is a little blurry, but I'm sure with some fiddling it would be OK.
Certainly I am reasonably happy with this result, but...
The Problem
It is very slow. I mean horribly slow. On my laptop this took roughly 60 seconds to create, Photoshop managed it in a few seconds. It gets worse for larger images since the strength of the blur has to be increased as the size of the image increases. I would be more than willing to sacrifice some quality of the blur if I could make reasonable gains in speed.
Attempted solution
After a lot of digging I stumbled across a method using an FFT to perform a blurring effect on this page, under the section "Blurring An Image - Low Pass Filtering".
This provides the following example:
Code: Select all
convert lena.png -fft \
\( -size 256x256 xc:black -fill white -draw "point 128,128" \
-alpha off -blur 0x16 -contrast-stretch 0 -write gaussian16.png \
-clone 0 -compose multiply -composite \) \
\( +clone -contrast-stretch 0 -evaluate log 10000 -write lena_gaussian16_spec.png \) \
-delete 0,3 +swap -ift lena_gaussian16_blur.png
So, in order to re-produce the result with my example source image I replaced the image used in the above example with my "street.jpg", fixed the dimensions and tried to produce a blurred image with the following code:
Code: Select all
convert.exe street.jpg -fft ( -size 800x571 xc:black -fill white -draw "point 400,285" -alpha off -blur 0x10 -contrast-stretch 0 -write gaussian.png -clone 0 -compose multiply -composite ) ( +clone -contrast-stretch 0 -evaluate log 10000 -write spec.png ) -delete 0,3 +swap -ift street_blur.png
I have been fiddling with the above example for quite a while, sometimes I manage to produce an image with some faint lines on it, or sometimes even a heavily distorted version of the original, but never something resembling a blur.
The Question(s)
- Broadly, how can I produce a reasonable quality but fast tilt shift effect?
- Is there a faster way to perform my working example, perhaps using some other obscure option to replace my use of blur? Or is this the fastest way to achieve the desired effect in this manner?
- Am I barking up the wrong tree by attempting to use an FFT? Even if I could get it to work could I ever get it to apply the gradient mask properly?