Page 1 of 1
Min and max values of LAB channels
Posted: 2016-08-10T13:13:27-07:00
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
Re: Min and max values of LAB channels
Posted: 2016-08-10T14:09:08-07:00
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
Re: Min and max values of LAB channels
Posted: 2016-08-10T14:13:45-07:00
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:
Re: Min and max values of LAB channels
Posted: 2016-08-10T16:27:27-07:00
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.
Re: Min and max values of LAB channels
Posted: 2016-08-10T22:46:22-07:00
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.
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
Re: Min and max values of LAB channels
Posted: 2016-08-10T23:03:37-07:00
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.
Re: Min and max values of LAB channels
Posted: 2016-08-10T23:15:59-07:00
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.