Page 1 of 1

Using mogrify and -clut option together

Posted: 2010-08-26T19:59:05-07:00
by skrandom
Hi, IM newbie here hoping for some help with applying a CLUT to an image with mogrify.

I'm able to apply a CLUT (with an alpha channel) to an image successfully using 'convert' but am having no success with trying to use 'mogrify' to overwrite the same image. My 'convert' command is thus:

Code: Select all

convert -alpha Off example.png -channel RGBA green_gradient.png -clut example_clut.png
Which takes this type of greyscale image with alpha (thumbnails don't show alpha):
Image
and applies a 256x1 CLUT (with an alpha channel) to produce this:
Image

Essentially, I'd like to do the same with 'mogrify' to change the original image. I get a segmentation fault error if I try and run either of these:

Code: Select all

mogrify -alpha Off example.png -channel RGBA green_gradient.png -clut example.png
mogrify -channel RGBA green_gradient.png -clut -alpha Off example.pngproduce the result with piping IM output 
and otherwise if my original image simply has it's alpha channel stripped if I run this:

Code: Select all

mogrify -alpha Off example.png -channel RGBA green_gradient.png -clut
And beyond that, I've just been guessing. I have managed to overwrite the original file using piped output, but want to avoid this if possible.

Thanks in advance.

Re: Using mogrify and -clut option together

Posted: 2010-08-26T20:10:02-07:00
by fmw42
I don't believe that mogrify allows a "second" image in the command line. It just processes each image in the directory per other commands. With -clut, you need a second look up table image. Thus it is not compatible with mogrify. Sorry. I think you will have to write a script loop to apply -clut to many images. Anthony can clarify or correct me if I am wrong.

Re: Using mogrify and -clut option together

Posted: 2010-08-26T20:22:08-07:00
by skrandom
fmw42 wrote:I don't believe that mogrify allows a "second" image in the command line. It just processes each image in the directory per other commands. With -clut, you need a second look up table image. Thus it is not compatible with mogrify. Sorry. I think you will have to write a script loop to apply -clut to many images. Anthony can clarify or correct me if I am wrong.
Sure, thanks. That's the conclusion I was getting to as well. I did see that -clut is mentioned in the mogrify documentation as being supported, but I've not been able to find examples anywhere.

Re: Using mogrify and -clut option together

Posted: 2010-08-26T20:23:52-07:00
by fmw42
Sure, thanks. That's the conclusion I was getting to as well. I did see that -clut is mentioned in the mogrify documentation as being supported, but I've not been able to find examples anywhere.
Where did you see this?

Well this page http://www.imagemagick.org/script/mogrify.php does list -clut. But I have to believe that it is in error.

From the mogrify page in Anthony's examples:


As "mogrify" deals with a single list of multiple output images, it can not support the combining of multiple images together. As such Image List and Sequence Operators will not work. That is you can not perform operations like "-fx", "+swap", "-composite", "-append", "-flatten", and "-layers" in a "mogrify" command.

I believe that -clut falls into this class as well

Re: Using mogrify and -clut option together

Posted: 2010-08-26T20:35:20-07:00
by fmw42
You could try various types of colorization of your image such as: -tint, +level-colors, -colorize, etc.

see
http://www.imagemagick.org/Usage/color/

or some of my scripts as well

Alternately, just write a script loop to process each of your images with your lut image and -clut.

Re: Using mogrify and -clut option together

Posted: 2010-08-26T20:39:07-07:00
by skrandom
fmw42 wrote: Where did you see this?
Well this page http://www.imagemagick.org/script/mogrify.php does list -clut. But I have to believe that it is in error.
Yep, that's the page.
fmw42 wrote: As "mogrify" deals with a single list of multiple output images, it can not support the combining of multiple images together. As such Image List and Sequence Operators will not work. That is you can not perform operations like "-fx", "+swap", "-composite", "-append", "-flatten", and "-layers" in a "mogrify" command.
-clut is also in the mogrify man page, and so are most of those other operations you've mentioned as well.
fmw42 wrote:I believe that -clut falls into this class as well
That makes sense. I've already prepared an alternative way of overwriting the original images:

Code: Select all

find . -name "*.png" -printf 'convert -alpha Off "%p" -channel RGBA green_gradient.png -clut png:- | convert png:- "%p"\n' | sh
and that works just fine. Might have to consider efficiency a bit more, but it does the job for more.

Cheers for the help.

Re: Using mogrify and -clut option together

Posted: 2010-08-29T18:43:32-07:00
by anthony
Convert can write the image back into an image it has read into memory -- no problems.

The output image is not opened until the end of the image processing is done.

Code: Select all

  find . -name "*.png" -printf 'convert -alpha Off "%p" -channel RGBA green_gradient.png -clut "%p"\n' | sh
PS: watch out for filenames containing quotes! or other shell meta characters such as '$' '\' etc...
Such things could break or even corrupt your script. Remember UNIX filenames can contain ANY charcater except nulls ('\0') and slashes '/'. That includes spaces, newlines, quotes, backslashes, etc etc etc.

Re: Using mogrify and -clut option together

Posted: 2010-08-29T19:05:58-07:00
by skrandom
anthony wrote:Convert can write the image back into an image it has read into memory -- no problems.

The output image is not opened until the end of the image processing is done.

Code: Select all

  find . -name "*.png" -printf 'convert -alpha Off "%p" -channel RGBA green_gradient.png -clut "%p"\n' | sh
Great; that'll save some time during processing.
anthony wrote: PS: watch out for filenames containing quotes! or other shell meta characters such as '$' '\' etc...
Such things could break or even corrupt your script. Remember UNIX filenames can contain ANY charcater except nulls ('\0') and slashes '/'. That includes spaces, newlines, quotes, backslashes, etc etc etc.
For sure. I've got the benefit of knowing this script will only ever be run on file names like 0.png and 1.png, but I'll keep it in mind for any future use cases.