Page 1 of 1

Is there a faster way than -fx?

Posted: 2007-11-27T11:25:59-07:00
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

Re: Is there a faster way than -fx?

Posted: 2007-11-27T12:09:19-07:00
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 .

Re: Is there a faster way than -fx?

Posted: 2007-11-27T14:25:49-07:00
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

Re: Is there a faster way than -fx?

Posted: 2007-11-27T17:48:10-07:00
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

Re: Is there a faster way than -fx?

Posted: 2007-11-27T18:22:27-07:00
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

Re: Is there a faster way than -fx?

Posted: 2007-11-28T10:49:36-07:00
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

Re: Is there a faster way than -fx?

Posted: 2007-11-28T16:05:33-07:00
by anthony
I would use a larger gradient image.

Re: Is there a faster way than -fx?

Posted: 2007-11-28T16:23:52-07:00
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

Re: Is there a faster way than -fx?

Posted: 2007-11-28T16:49:45-07:00
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.