How to get max saturation from image sequence

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
Przemek89
Posts: 3
Joined: 2017-02-19T14:55:24-07:00
Authentication code: 1151

How to get max saturation from image sequence

Post by Przemek89 »

I used

Code: Select all

convert *.jpg -maximum OUT.jpg
to get the brightest pixel and set it in OUT.jpg

Is it possible to do the same with saturation?
Get the most colorful pixel and set it in out.jpg...

Something like:

Code: Select all

convert *.jpg -maximumSaturation OUT.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

I can't see an easy way of doing this.

It is easy to set the output pixel to the highest saturation: just convert to HSL and select the saturation channel. But the output will contain only the saturation, not the hue and lightness.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to get max saturation from image sequence

Post by fmw42 »

I do not see any command -maximum for IM 6 or 7 at http://www.imagemagick.org/script/comma ... ptions.php.

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

"-maximum" is there, though not in the contents at the top. [strike]I think it is a synonym for "-statistic maximum".[/strike]

What was I thinking? As Fred says below, it is "-evaluate-sequence max".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to get max saturation from image sequence

Post by fmw42 »

Thanks, snibgo. It is clearly an legacy command and I have never used it in all my years of using IM. But it says:
return the maximum intensity of an image sequence.
This would make me believe it was a synonym for -evaluate max.

I would suggest the OP use whatever is the proper current option that is consistent with what he is trying to do.

P.S. The porting guide for IM 7 says it is deprecated but allowed for now.
-maximum
Replaced by -evaluate-sequence Max.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

Oops, yes, as you say. Corrected above.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to get max saturation from image sequence

Post by fmw42 »

You could try getting the max saturation and max brightness from colorspace HSL and combine that with any of your image's hue channel.

Code: Select all

convert *.jpg -colorspace HSB -channel g -separate -evaluate-sequence max maxsat.png
convert *.jpg -colorspace HSB -channel b -separate -evaluate-sequence max maxbri.png
convert anyimage.jpg -colorspace HSB -channel r -separate maxsat.png maxbri.png -set colorspace HSL -combine -colorspace sRGB result.png
This assume that all images are registered and are for the same scene.

I assume your IM version is not too old that -evaluate-sequence did not exist. If so, then use your -maximum.

Can you post about 6 of your images to some free hosting service such as dropbox.com and put the URLs here? Then we can test a few ideas.

Also what is your IM version and platform/OS, since syntax may differ.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

@Przemek89: Can you provide some sample inputs? You can upload to somewhere like dropbox.com and paste URLs here. That will help us understand what you want.

If there are only two inputs, we can make an output where each pixel is taken from whichever source has the greatest saturation at that pixel. The method is: make an output of the saturation channel only, where this is the maximum. Compare this to the saturation of the first image. This gives us a mask which says whether the pixel should come from the first or second image, so we can do a masked composite.

We can iterate that method over (n) images: apply it to the first two images, then to the result of that and the third image, then the result of that and the fourth image, and so on.

That's the simplest way [EDIT: at the command level] I can think of to do what I think you want. If, instead, you want the saturation of each pixel to be the maximum of the inputs but the hue and lightness could come from any input, the method shown by Fred is simpler and faster.

EDIT: A simpler and quicker way would be to write a process module that does what "-evaluate max" does, but for saturation instead of lightness.
snibgo's IM pages: im.snibgo.com
Przemek89
Posts: 3
Joined: 2017-02-19T14:55:24-07:00
Authentication code: 1151

Re: How to get max saturation from image sequence

Post by Przemek89 »

@snibgo: I searched for "evaluate max" source code here:
https://github.com/ImageMagick/ImageMagick
but i coud not find it.
If code uses HSL model to get the brightest pixel from many images, it should not be complicated to change it to saturation.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

See magick\statistic.c

EDIT: the v6 directory is "magick". The v7 directory is "MagickCore".
snibgo's IM pages: im.snibgo.com
Przemek89
Posts: 3
Joined: 2017-02-19T14:55:24-07:00
Authentication code: 1151

Re: How to get max saturation from image sequence

Post by Przemek89 »

I think that it could be done with:
https://www.imagemagick.org/script/fx.php
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

Almost anything can be done with "-fx", provided you don't mind it taking a long time.

I have an idea for doing it in a single "convert", quickly and easily. But I have no inputs to test it on.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get max saturation from image sequence

Post by snibgo »

Okay, I created some inputs. The IM v6, Windows BAT syntax, command is:

Code: Select all

convert ^
  maxsat_r.jpg maxsat_g.jpg maxsat_b.jpg ^
  NULL: ^
  ( -clone 0--2 ^
    -colorspace HCL -channel G -separate +channel ^
    NULL: ^
    ( -clone 0--2 ^
      -evaluate-sequence Max ^
    ) ^
    -compose Difference -layers Composite ^
    -fill White +opaque Black -negate ^
  ) ^
  -compose CopyOpacity -layers Composite ^
  -compose Over -layers Merge ^
  maxsat_out.jpg
Replace my three inputs with any number of same-size images. I use JPEGs only for web performance.

I use the Chroma channel of HCL because I prefer it to HSL.

Inputs:
Image
Image
Image

Output:
Image
snibgo's IM pages: im.snibgo.com
Post Reply