Using mogrify and -clut option together

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
skrandom

Using mogrify and -clut option together

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using mogrify and -clut option together

Post 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.
skrandom

Re: Using mogrify and -clut option together

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using mogrify and -clut option together

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using mogrify and -clut option together

Post 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.
skrandom

Re: Using mogrify and -clut option together

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Using mogrify and -clut option together

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
skrandom

Re: Using mogrify and -clut option together

Post 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.
Post Reply