Try using -color-matrix. I have cropped the image in a region inside the gray card and get its average and divide that into 0.5 to get a ratio of true gray to average gray for each channel. See
http://www.imagemagick.org/script/comma ... lor-matrix
In unix syntax, this would be either of the following:
Code: Select all
infile="8Mvyi.jpg"
gray=0.5
rratio=`convert "$infile" -crop 90x40+106+208 +repage -format "%[fx:$gray/mean.r]" info:`
gratio=`convert "$infile" -crop 90x40+106+208 +repage -format "%[fx:$gray/mean.g]" info:`
bratio=`convert "$infile" -crop 90x40+106+208 +repage -format "%[fx:$gray/mean.b]" info:`
echo "$rratio $gratio $bratio"
convert "$infile" -color-matrix \
"$rratio 0 0 \
0 $gratio 0 \
0 0 $bratio" result.jpg
Code: Select all
infile="8Mvyi.jpg"
gray=0.5
declare `convert "$infile" -crop 90x40+106+208 +repage -format "rratio=%[fx:$gray/mean.r]\ngratio=%[fx:$gray/mean.g]\nbratio=%[fx:$gray/mean.b]\n" info:`
echo "$rratio $gratio $bratio"
convert "$infile" -color-matrix \
"$rratio 0 0 \
0 $gratio 0 \
0 0 $bratio" result.jpg
However, if I measure the gray card in the result from Lightroom, I find a gray value, not 0.5 (middle gray), but
Code: Select all
convert YQykH.jpg -crop 90x40+106+208 +repage -format "%[fx:mean]" info:
0.67397
So I use that value, then
Code: Select all
infile="8Mvyi.jpg"
gray=0.67397
declare `convert "$infile" -crop 90x40+106+208 +repage -format "rratio=%[fx:$gray/mean.r]\ngratio=%[fx:$gray/mean.g]\nbratio=%[fx:$gray/mean.b]\n" info:`
echo "$rratio $gratio $bratio"
convert "$infile" -color-matrix \
"$rratio 0 0 \
0 $gratio 0 \
0 0 $bratio" result2.jpg
Adjust the gray=value as desired.
Note that Wikipedia specifies the sRGB color for a gray card as 46.6% or 0.466. See
https://en.wikipedia.org/wiki/Middle_gray
Alternately, Lightroom is likely processing this in linear RGB. So this looks like what they are doing:
Code: Select all
infile="8Mvyi.jpg"
gray=0.5
declare `convert "$infile" -colorspace RGB -crop 90x40+106+208 +repage -format "rratio=%[fx:$gray/mean.r]\ngratio=%[fx:$gray/mean.g]\nbratio=%[fx:$gray/mean.b]\n" info:`
echo "$rratio $gratio $bratio"
convert "$infile" -colorspace RGB -color-matrix \
"$rratio 0 0 \
0 $gratio 0 \
0 0 $bratio" -colorspace sRGB result3.jpg