Is there a faster way than -fx?

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?".
Post Reply
zer0energy

Is there a faster way than -fx?

Post by zer0energy »

Hi - I'm trying to colorize an image that I captured from a grayscale camera. First, I blur the image to reduce the effects of noise. Then I colorize it by multiplying the grayscale value with the desired color on a pixel-by-pixel basis. The functionality is pretty much exactly what I wanted to do, but it's very slow. Is there a better way to do what I'm trying to do? The command I'm using (in a DOS Batch file, hence the double quotes for the fx command) is:

convert x0yn.bmp -blur 0x3 xc:IndianRed2 -size 1x1 -fx "u*v.p{0,0}" x0yn.png

I really appreciate the help! Thanks!

Matt
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Is there a faster way than -fx?

Post by magick »

We tried your command with the latest ImageMagick release, 6.3.7-1, and it ran in just over 3 seconds on the 640x480 ImageMagick logo. The -fx option is interpreted. To speed it up you can translate your expression into a compiled image filter. See http://www.imagemagick.org/script/archi ... hp#filters .
zer0energy

Re: Is there a faster way than -fx?

Post by zer0energy »

Thanks for the quick response! I'll look carefully at your solution. I know 3 seconds doesn't seem like a lot, but we're processing 1024x768 images and a lot of them so it adds up quickly. I'll also look at shrinking the images to speed things up.

Maybe there's a completely different way to do roughly what I'm trying to do. Is there some other way to use the intensity value from one image, but the hue and saturation from another?

Cheers,
Matt
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is there a faster way than -fx?

Post by anthony »

There are a number of other methods, especially for gray scale.

You can use -tint, which will tine grays while leaving white and black alone. You can use -colorize, though that colors images by de-contrasting the image (overlays a image of semi-transparent constant color). The best method however is a new one that was only recently converted from an -fx solution to a direct operator....

The -clut operator was added to IM v6.3.5-8. It takes a gray scale image and a color gradient image (horizontal or vertical) and replaces each gray scale value with the corresponding value from the pre-prepared color gradient. This is probably ideal to your problem. However it is NEW and may not be available on your installed version of IM.

See IM Examples, Color Lookup tables
http://imagemagick.org/Usage/#clut
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
zer0energy

Re: Is there a faster way than -fx?

Post by zer0energy »

Hello Anthony,

That looks like exactly what I'm looking for! I'll post my revised command line when I get into the office tomorrow. Thanks so much for pointing me in the right direction! :lol:

Matt
zer0energy

Re: Is there a faster way than -fx?

Post by zer0energy »

Here's the new command. I get roughly a 4x speedup using this over the original version:

convert x0yn.bmp -blur 0x3 -size 10x100 gradient:black-IndianRed2 -clut x0yn.png

Thanks again for the help!!

Matt
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is there a faster way than -fx?

Post by anthony »

I would use a larger gradient image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
zer0energy

Re: Is there a faster way than -fx?

Post by zer0energy »

Hi Anthony,

I assumed the color interpolation would take care of any incorrect sizing. What would you suggest as a reasonable size? Would you use 1x256? 1x16384? How do you determine the proper size of the LUT?

Matt
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is there a faster way than -fx?

Post by anthony »

The interpolation does work, but it also falls down a little at extremes.
Try a two pixel gradient to see what I mean. For example...

Code: Select all

convert -size 100x100 gradient: -size 1x2 gradient:red-blue -clut x:
replace x: with win: under PC windows

I am currently adjusting the -clut function to try to fix that problem particularly at the black (top in the above example) end, but that may take time to filter down to you.

For Q8 256 will be fine, for a Q16 IM at least 512 is recommended.

Astually the whole 'colors' IM Examples page is now needing a re-write as we have new developments planned for color enhancments as well as the use of -clut to handle much of what use to be done with -fx.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply