I have a script that uses a lot of CPU time. One thing it does is a distortion with a LUT map. I just realized I could do the same effect with a barrel distortion. Is a barrel distortion less CPU intensive than a LUT map distortion? The script runs on a shared hosting web server, so I really need to make it leaner.
Also, is barrel distortion implemented in the PerlMagick API? I can't find it anywhere.
Barrel distortion vs. LUT map distortion
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Barrel distortion vs. LUT map distortion
Ryland wrote:I have a script that uses a lot of CPU time. One thing it does is a distortion with a LUT map. I just realized I could do the same effect with a barrel distortion. Is a barrel distortion less CPU intensive than a LUT map distortion? The script runs on a shared hosting web server, so I really need to make it leaner.
Also, is barrel distortion implemented in the PerlMagick API? I can't find it anywhere.
Depends upon what you mean by LUT map. If you mean using -fx, then -distort barrel will be faster. If you mean -clut, then -clut will be faster. If you mean -displace, then probably (?) -displace is faster, but Anthony is the last word in all of this.
Don't know about implementation in PerlMagick?
Re: Barrel distortion vs. LUT map distortion
I'm using distortion maps similar to the ones described here, but I hardly ever use ImageMagick from the command line, I always use it via PerlMagick. I'm guessing it uses -fx, but I don't know for sure. Here's the syntax I use, if it helps:Depends upon what you mean by LUT map. If you mean using -fx, then -distort barrel will be faster. If you mean -clut, then -clut will be faster.
Code: Select all
$img->Composite(image=>$disp1,compose=>'Displace',blend=>"0x10",gravity=>"NorthWest");
I wouldn't be surprised if it isn't implemented in PerlMagick, many things aren't, and the things that are often use different names or parameters.Don't know about implementation in PerlMagick?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Barrel distortion vs. LUT map distortion
You are using a displacement map via -displace and that should be as fast or faster than -distort barrel, except for the time that it takes you to create the displacement maps themselves. So possibly -distort barrel overall may be faster. You will just have to try it and see which is faster. -displace does not use -fx, as far as I know.Depends upon what you mean by LUT map. If you mean using -fx, then -distort barrel will be faster. If you mean -clut, then -clut will be faster.
I'm using distortion maps similar to the ones described here, but I hardly ever use ImageMagick from the command line, I always use it via PerlMagick. I'm guessing it uses -fx, but I don't know for sure. Here's the syntax I use, if it helps:
Code:
$img->Composite(image=>$disp1,compose=>'Displace',blend=>"0x10",gravity=>"NorthWest");
Anthony should be able to set this all straight. But the bottom line is try both to see which is faster.
Re: Barrel distortion vs. LUT map distortion
The displacement map is a static GIF file, so that isn't a factor.fmw42 wrote:You are using a displacement map via -displace and that should be as fast or faster than -distort barrel, except for the time that it takes you to create the displacement maps themselves. So possibly -distort barrel overall may be faster.
I'm not necessarily concerned with speed so much as how much CPU it uses. If one way is faster but eats a lot of CPU and the other is slower but uses much less CPU, I'll go with the slower one. I don't know how to go about finding that out, though.fmw42 wrote: You will just have to try it and see which is faster. -displace does not use -fx, as far as I know.
Anthony should be able to set this all straight. But the bottom line is try both to see which is faster.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Barrel distortion vs. LUT map distortion
The Perl API method you are using is the same as described in
http://www.imagemagick.org/Usage/compose/#displace
It is currently a 'composition' -displace method even though really it does not fit in that classification of image operation. The -fx LUT methods are working for a eventual replacement.
The -displace method is a simple direct lookup (one lookup of the source image for each output image.
The -distort Barrel however I believe we have fixed to use Area Resampling, allowing better results for areas of image compression, producing better images, though that would make it slower. You can turn of EWA using -filter point before -distort.
Other than that the two should be about the same speed.
I am planning at some point to properly implement displacement mapping, with Area Sampling for better results, but time line for that is known at this point. It will probably be a special "convert" form of -distort-lut method that will not only allow relative displacements, but also absolute displacement mappings.
http://www.imagemagick.org/Usage/compose/#displace
It is currently a 'composition' -displace method even though really it does not fit in that classification of image operation. The -fx LUT methods are working for a eventual replacement.
The -displace method is a simple direct lookup (one lookup of the source image for each output image.
The -distort Barrel however I believe we have fixed to use Area Resampling, allowing better results for areas of image compression, producing better images, though that would make it slower. You can turn of EWA using -filter point before -distort.
Other than that the two should be about the same speed.
I am planning at some point to properly implement displacement mapping, with Area Sampling for better results, but time line for that is known at this point. It will probably be a special "convert" form of -distort-lut method that will not only allow relative displacements, but also absolute displacement mappings.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/