P.S. Again,
If you do not need the gamma part of level, then you can do the same
thing automatically with
convert image1.png -contrast-stretch 0% image2.png
It finds the min and max automatically and stretches the image
linearly so that the min becomes black and the max becomes white.
"The channels are stretched in concert. Specify -channel to normalize
the RGB channels individually."
see http://www.imagemagick.org/script/command-line-options.php#contrast-stretch
____________________________________
P.S.
I am not sure you need to do these by channel for min and max as I
think you get that naturally from the simpler formula,
__________________________________________
Prior to IM 6.3.9:
data=`convert image -verbose info:`
min=`echo "$data" | sed -n '/^.*[Mm]in:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
max=`echo "$data" | sed -n '/^.*[Mm]ax:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
mean=`echo "$data" | sed -n '/^.*[Mm]ean:.*[(]\([0-9.]*\).*$/{
s//\1/; p; q; }'`
std=`echo "$data" | sed -n '/^.*[Ss]tandard.*[(]\([0-9.]*\).*$/{
s//\1/; p; q; }'`
reports values in range 0 to 1
String Formats: Min, Max, Mean, Standard Deviation Introduced in IM 6.3.9-1
convert image -format "%[min]" info:
convert image -format "%[max]" info:
convert image -format "%[mean]" info:
convert image -format "%[standard-deviation]" info:
reports values in range 0 to QuantumRange
Above deprecated (but still supported) in IM 6.4.0-11 but now
convert image -format "%[fx:image.minima]" info:
convert image -format "%[fx:image.maxima]" info:
convert image -format "%[fx:image.mean]" info:
convert image -format "%[fx:standard_deviation]" info:
reports values in range 0 to 1. But you can now do math calculations
within these.
To get them by channel, you need to do the following:
minred=`convert image -channel Red -separate "%[fx:100*image.minima]" info:`
reports percent values (i.e. 0 to 100)
or
minred=`convert image -channel Red -separate
"%[fx:QuantumRange*image.minima]" info:`
reports values in range 0 to QuantumRange (8-bit: 0 to 255; 16-bit 0 to 65535)
Then you can substitute the variables into:
min=`convert xc: -format "%[fx:min($minred,$mingreen,$minblue)]" info:`
max=...
Then you can substitute these variables into:
convert image.jpg
-level $min,$max image2.jpg
Note: if using percent values then you need to add the percent sign %
convert image.jpg
-level $min%,$max% image2.jpg
Hello,
For proper color transformation with -level you have to check min,max
color values for each image separately. Is there a way to do it more or
less automatically with IM or other cross platform tool (Windows and
Linux)?
identify -verbose gives histogram values but 1) it takes ages to get
that info for big files 2) isn't easy to parse.
Correct info for level is something like:
convert image.jpg
-level (min(min r, min g, min b)),(max(max r, max g, max b)) image2.jpg
TIA
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users