Tilt Shift

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?".
gritter
Posts: 11
Joined: 2013-06-29T12:13:57-07:00
Authentication code: 6789

Re: Tilt Shift

Post by gritter »

fmw42 wrote:Did you see my comment above that if you use -compose blur and set one dimension to 0, it runs very quickly. I showed a result.

Most of your pictures did not show up. So I am not sure what you did in PS. Nevertheless, as above, you can achieve a similar result in a timely manner with -compose blur
Yes, I did see your previous example and I have just tested it (sorry for the delay). On my machine it took ~12 seconds, which is a damn sight faster than what I have been using, and the quality is acceptable.

I should point out that, while this machine isn't the fastest, the machine the command will ultimately be running on is a lot faster, but then it will be processing a lot more images, so the improvement in speed is important.

I'm sorry the pictures didn't show up, I wonder if other people can see them or if there is a problem with the image host I am using. Just for reference I will describe the steps for photoshop:

1) Open the source image and the mask image.
2) With the mask image visible use ctrl-a to marquee the entire image, then use ctrl-c. (or command-a etc...) to copy to the clipboard.
3) Switch to the source image and open the channels palette.
4) Create a new channel.
5) Select the new channel and use ctrl-v to paste the mask into it.
6) Hold ctrl and click the thumbnail for the new channel to produce a selection based on the mask.
7) Click the RGB channel to show the source image.
8) Go to Filters > Blur > Lens blur and apply a blur of, say, 50 pixels.
9) ctrl-d to clear the selection.
10) Done.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tilt Shift

Post by fmw42 »

Thanks. I was trying to work with the layers mask, but could not get it to work. It does work when you put the mask into an alpha channel.

Lens blur is different from gaussian blur (as per IM copy blur), so the results will be some different.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tilt Shift

Post by anthony »

fmw42 wrote:Did you see my comment above that if you use -compose blur and set one dimension to 0, it runs very quickly. I showed a result.
While that image (horizontal only blur) is not right. I wonder if you can do this as a two pass variable blur.

Do it once with one value 0, then do it again with the other value 0. May not be as exact but it may be faster!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tilt Shift

Post by fmw42 »

Anthony wrote:Do it once with one value 0, then do it again with the other value 0. May not be as exact but it may be faster!
Yes that does work rather faster than the 2D blur.


convert street.jpg mask.png -compose Blur -set option:compose:args 25x0 -composite \
mask.png -compose Blur -set option:compose:args 0x25 -composite street_comp_blur25x2.jpg

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Tilt Shift

Post by snibgo »

Yup, that's quicker. On a 7360x4912 image, using a gradient mask, blur 11x11 took 23 mins 50 secs, where blur 11x0 followed by blur 0x11 took 5 mins 15 secs. Visually identical. Thanks.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tilt Shift

Post by anthony »

Example of a two pass tilt-shift added to IM examples
http://www.imagemagick.org/Usage/photos/#tilt_shift
as always give it a few hours for the new 'speed optimization' to appear.

convert beijing_md.jpg -sigmoidal-contrast 15x30% \
\( +clone -sparse-color Barycentric '0,0 black 0,%h gray80' \
-solarize 50% -level 50%,0 -write mpr:blur_map \) \
-compose Blur -set option:compose:args 5x0 -composite \
mpr:blur_map \
-compose Blur -set option:compose:args 0x5 -composite \
beijing_model_2pass.jpg

I am certain a 'clone' method can be used instead of saving the mapping image using a MPR: register, But it works.

It is not as 'exact', and I believe doing a vertical blur before a horizontal may be more exact. as it is the horizontal that is constant along the direction of the blur (so do it last). I have not tried though.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tilt Shift

Post by fmw42 »

Anthony wrote:It is not as 'exact', and I believe doing a vertical blur before a horizontal may be more exact. as it is the horizontal that is constant along the direction of the blur (so do it last). I have not tried though.
horizontal then vertical
convert street.jpg mask.png -compose Blur -set option:compose:args 25x0 -composite mask.png -compose Blur -set option:compose:args 0x25 -composite street_comp_blur25x2.jpg

vertical then horizontal
convert street.jpg mask.png -compose Blur -set option:compose:args 0x25 -composite mask.png -compose Blur -set option:compose:args 25x0 -composite street_comp_blur25x2b.jpg

compare -metric rmse street_comp_blur25x2.jpg street_comp_blur25x2b.jpg null:
188.508 (0.00287644)

Very slight difference visually (at the corner of the dark roof overhang) with the second slightly better in my opinion than the first.
gritter
Posts: 11
Joined: 2013-06-29T12:13:57-07:00
Authentication code: 6789

Re: Tilt Shift

Post by gritter »

I apologise for not posting for a while, IRL stuff came up etc.

I also appreciate everyone's input in this thread, it was very helpful having all the different ideas. But for my purposes the solutions offered are just too slow so I will have to shelf the project until I can find a solution.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tilt Shift

Post by fmw42 »

Is it too slow even use the two pass vertical then horizontal -compose blur?
gritter
Posts: 11
Joined: 2013-06-29T12:13:57-07:00
Authentication code: 6789

Re: Tilt Shift

Post by gritter »

Again, I apologise for the delay.
fmw42 wrote:Is it too slow even use the two pass vertical then horizontal -compose blur?
I tested the 2-pass technique and it took ~7 seconds on the street image, which is a huge improvement in speed. I will have to test it on some real images to determine whether it is fast enough, but I regretfully suspect that it won't be enough.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tilt Shift

Post by fmw42 »

Do you have a multi-core processor and OpenMP enabled?
gritter
Posts: 11
Joined: 2013-06-29T12:13:57-07:00
Authentication code: 6789

Re: Tilt Shift

Post by gritter »

fmw42 wrote:Do you have a multi-core processor and OpenMP enabled?
Yes (2 cores on this box), and I am guessing no, since my CPU monitor only goes up to 50%.

It's not particularly important though, since I was hoping to run several instances in parallel.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tilt Shift

Post by fmw42 »

OpenMP allows processing speed up by utilizing more than one core. It is not like OpenCL for display hardware speedup for which there are only a few current IM functions that will utilize OpenCL.

If

convert -version

lists OpenMP then it is enabled and using your two cores as best it can.
Post Reply