Min and max values of LAB channels

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
tcrass
Posts: 38
Joined: 2009-11-22T11:12:52-07:00
Authentication code: 8675309

Min and max values of LAB channels

Post by tcrass »

Hi there,

I've got a bunch of sRGB images with 16 bit color depth, and I'd like to now the minimum and maximum pixel values (in percent) of each channel after converting the image to LAB -- preferably as a one-liner per channel. I was tinkering a bit with

Code: Select all

identify -format '%[fx:minima*100],%[fx:maxima*100]' -colorspace LAB -channel A image.tif
but the -channel settings has no effect, I always seem to get the values for the L channel.

Any thoughts...?

Cheers --

Torsten
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Min and max values of LAB channels

Post by fmw42 »

IM uses -channel A for alpha. See http://www.imagemagick.org/script/comma ... hp#channel. For other colorspace, use R,G,B for each of the first 3 channals.
preferably as a one-liner per channel
Try using convert in place of identify.

Code: Select all

convert image.tif -colorspace LAB -separate +channel -format '%[fx:minima*100],%[fx:maxima*100]\n' info:
Example using the IM internal rose: image

Code: Select all

convert rose: -colorspace LAB -separate +channel -format '%[fx:minima*100],%[fx:maxima*100]\n' info:
14.6731,100
37.464,81.0224
30.0847,71.0552
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Min and max values of LAB channels

Post by snibgo »

Do you want 6 values, for the min and max of each of the L, a* and b* channels?

I would use convert, not identify.

Code: Select all

convert image.tif -colorspace Lab -format "%[fx:minima.r*100] %[fx:maxima.r*100] %[fx:minima.g*100] %[fx:maxima.g*100] %[fx:minima.b*100] %[fx:maxima.b*100]" info:
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Min and max values of LAB channels

Post by anthony »

The -channel values refer to the channels for colorspaces RGBA or CMYKA.
Thus 'A' in the original example refers to the alpha channel (which is probably pure white or opaque) and not the 'A' channel of "LAB".
To get the 'A' channel of 'LAB' you would need to use name for the second RGB channel or "-channel G"
Yes it seems silly, but it is the way the -channel are 'named'.

For details of getting the various channels see IM Examples,
http://www.imagemagick.org/Usage/color_basics/#channels

Also note that if your ImageMagick is not HDRI, then the channel values will have an offset.
See the example in Perceptual Colorspaces
http://www.imagemagick.org/Usage/color_ ... rspace_LAB

Note how the 'A' and 'B' channel images are mostly a mid-tone grey color do to the offset.
By doing this it makes the various image processing algorithms work correctly with unsigned integers. Something that is not a problem with HDRI versions which use a floating point store for the images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tcrass
Posts: 38
Joined: 2009-11-22T11:12:52-07:00
Authentication code: 8675309

Re: Min and max values of LAB channels

Post by tcrass »

Hi there,

and thank you so much for all your advice! The trick was -- apart from correct channel naming -- the "dot channel" notation like in "maxima.r". I had tried it the other way round ("r.maxima", thinking "the red channel's maxima"), but it obviously didn't work.
fmw42 wrote:IM uses -channel A for alpha. See http://www.imagemagick.org/script/comma ... hp#channel. For other colorspace, use R,G,B for each of the first 3 channals.
anthony wrote:The -channel values refer to the channels for colorspaces RGBA or CMYKA.
Thus 'A' in the original example refers to the alpha channel (which is probably pure white or opaque) and not the 'A' channel of "LAB".
To get the 'A' channel of 'LAB' you would need to use name for the second RGB channel or "-channel G"
Yes it seems silly, but it is the way the -channel are 'named'.
Well, the only one silly around here was apparently me -- yes, I had read about channel designations in IM some time (years?) ago, but complete forgot about it...
fmw42 wrote:Try using convert in place of identify.
snibgo wrote:I would use convert, not identify.
Any reason why you guys prefer "convert" to "identity"? Is it becaues it supports the -separate operator?

Thanks again --

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

Re: Min and max values of LAB channels

Post by anthony »

"identify" is a 'simplified' command for quick use, and when it comes down to it is equivalent to

convert image options info:

Basically you can do a lot more with "convert" (or in IMv7 "magick"), for example process the image in some way before getting information about the image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Min and max values of LAB channels

Post by snibgo »

When I'm processing an image, I use convert. True, in this case, we are not storing the processed image to a file, but we are still processing it (changing the colorspace).

I'm never quite sure of the order operations are executed in identify. And many operations are not available in identify.

In v6 "convert" is the general-purpose tool. I don't think "identify" can do anything that "convert" can't.

I recently reported a problem where a simple non-processing identify takes massively longer than convert. (See viewtopic.php?f=3&t=30254 ) This further discourages me from using it.
snibgo's IM pages: im.snibgo.com
Post Reply