Page 2 of 3
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-22T07:41:47-07:00
by snibgo
As Bonzo says, you need spaces. The clue is in the message:
Code: Select all
convert.exe: unable to open image `(reference.jpg': No such file or directory @ error/blob.c/OpenBlob/2638.
convert is looking for a filename that starts with an open bracket.
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-22T08:28:35-07:00
by rcolba
OK, I got it running. Thank you for your input.
My final solution is the following in a batch file:
@echo off
if [%1]==[] goto :eof
:loop
convert %1 ( +clone ( wbref.jpg -gravity Center -crop "50x50+0+0" -scale "1x1" -negate ) +dither -interpolate Integer -clut ) -compose Overlay -composite %~n1_wb.jpg
shift
if not [%1]==[] goto loop
on which you can drop multiple images. The convert function will correct the white balance of each of them relative to a reference image for the white balance named wbref.jpg placed in the same folder and save them back with a _wb suffix to the filename.
Unfortunately it seems as if with this method, images also tend to get darker than if I manually corrected their white balance in Lightroom.
Robert
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-22T08:38:40-07:00
by Bonzo
If your original images are in RAW you may need to edit the delgates.xml file
I have problems with CR2 files and from memory I needed to change:
Code: Select all
<delegate command="dcraw.exe -6 -w -O "%u.ppm" "%i"" stealth="True" decode="dng:decode"/>
To
<delegate command="dcraw.exe -4 -w -O "%u.ppm" "%i"" stealth="True" decode="dng:decode"/>
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-22T09:53:48-07:00
by snibgo
I might point out that the above methods work because the grey patch, as photographed, has a lightness of about 50%. If it was lighter or darker, it would adjust the lightness of the result, generally creating a colour shift.
This can be cured by ensuring the patch has a lightness of 50%. Windows script:
Code: Select all
convert mainky.jpg ^
( reference.jpg -gravity center -crop "50x60+0+0" ^
-scale "1x1^!" -negate ^
-set colorspace RGB ^
-colorspace HSL -channel Lightness -evaluate set 50%% -colorspace RGB ^
-set colorspace sRGB ^
-scale "400x300^!" ^
) ^
-compose overlay -composite ^
main_fixed4.jpg
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-22T23:28:08-07:00
by rcolba
Thank you for this important information,
Can I also get this running somehow without giving the file size 400x300 ? I would like to use it on files with different sizes.
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-23T00:58:38-07:00
by snibgo
Code: Select all
FOR /F "tokens=1,2" %%i IN ('%IM%identify -format "%%w %%h" %1') DO (
set WIDTH=%%i
set HEIGHT=%%j
)
Then use those environment variables in the script.
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-23T01:04:39-07:00
by Bonzo
That is a useful piece of code snibgo; I may have to put another example on my website examples using it
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-23T01:25:31-07:00
by rcolba
Hi snibgo,
Thank you for your fast feedback.
I'm not in expert in batch file/IM syntax. Could you explain where I have to put this code exactly in my script posted before?
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-23T14:59:00-07:00
by snibgo
rcolba wrote:Can I also get this running somehow without giving the file size 400x300 ?
This is the size (width and height) of the image. You can get these dimensions by inserting this earlier in the script:
Code: Select all
FOR /F "tokens=1,2" %%i IN ('%IM%identify -format "%%w %%h" %1') DO (
set WIDTH=%%i
set HEIGHT=%%j
)
and then using %WIDTH%x%HEIGHT% insead of 400x300.
If you don't need the dimensions, you don't need to do this.
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-26T00:15:02-07:00
by rcolba
Hi,
Here is my solution for a batch file for white balance correction on multiple files using as a reference a file called
wbref.jpg (placed in the same folder) of a white or grey card (using the 50 x 50 pixels center of it) . (Win7/ImageMagick-6.8.0-Q16)
Thanks for everybody's input,
Robert
Code: Select all
@echo off
if [%1]==[] goto :eof
:loop
FOR /F "tokens=1,2" %%i IN ('%IM%identify -format "%%w %%h" %1') DO (
set WIDTH=%%i
set HEIGHT=%%j
)
convert %1 ^
( wbref.jpg -gravity center -crop "50x50+0+0" ^
-scale "1x1^!" -negate ^
-set colorspace RGB ^
-colorspace HSL -channel Lightness -evaluate set 50%% -colorspace RGB ^
-set colorspace sRGB ^
-scale "%WIDTH%x%HEIGHT%^!" ^
) ^
-compose overlay -composite ^
%~n1_wb.jpg
shift
if not [%1]==[] goto loop
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-26T13:27:15-07:00
by fmw42
What or where can one fine the file wbref.jpg?
Just curious how your approach compares to just using -color-matrix. See
http://www.imagemagick.org/script/comma ... lor-matrix, where you compute the r,g,b ratios using the averages of those pixels closest to some desired gray or white and the reference gray or white.
I have done the latter from a combination of saturation and brightness from HSB.
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-26T14:49:42-07:00
by Bonzo
I would say make an image of your own fmw42; it is 18% grey whatever that is. There are some links here:
http://www.workwithcolor.com/gray-card-6475.htm
I assume downloading this and using on the PC would work but printing it would depend on the setup of the printer? Was the OP's image taken from his camera I wonder; it is also a jpg and is it still an 18% grey after compression?
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-26T15:27:46-07:00
by fmw42
It would be nice if rcolba would provide a link to an input and output example and his wbref.jpg so that we really understand what he is doing or trying to do.
P.S. According to
http://en.wikipedia.org/wiki/Gray_card an 18% graycard as shown gives color values of #D6D6D6 or rgb(214,214,214) and seems to me to be much too bright (light). That is not mid gray. However, I am not that much of a photographer to know how to translate Percent graycards into hex or rgb values.
On the other hand, from
http://en.wikipedia.org/wiki/Middle_gray, it seems that
"middle gray was defined as the geometric mean intensity between a white and a black intensity that are in a ratio of 60:1. That is equivalent to 12.9% of the white intensity."
where geometric mean is given by
http://en.wikipedia.org/wiki/Geometric_mean
However, right now I don't see how you can do sqrt((60x255)x0) and get anything but 0? So I obviously do not understand this yet.
It also says:
"In the sRGB color space, middle gray is equivalent to 46.6% brightness (i.e 50%,0,0 for LAB) In 24-bit color, this is rounded to RGB value (119,119,119) or #777777." See
http://www.brucelindbloom.com/index.htm ... lator.html
Which makes more sense, but I am not sure if it is for 18% or 13%?
This reference is interesting but does not clarify further
http://books.google.com/books?id=1JL2jF ... 25&f=false
This is a bit more helpful with several values, but does not agree with Lindstrom's calculator,
http://www.workwithcolor.com/gray-card-6475.htm
This one gives another value
http://www.luminous-landscape.com/forum ... #msg189465
This seems close to Lindbloom's values
http://www.pentaxforums.com/forums/pent ... -card.html
According to the following http://forums.dpreview.com/forums/thread/2938408 (with an approximation to sRGB by using gamma=1/2.2=.4545)
18% Gray card = (0.18^1/2.2) = 0.4587. Thus 0.4587*255 = 117
So
12% Gray card would be 255*(0.12^0.4545) => 97
and
13% Gray card would be 255*(0.13^0.4545) => 101
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-26T16:49:17-07:00
by snibgo
Don't make the mistake of thinking that a grey card should give any particular pixel values. Ideally, it should give the same value for the R, G and B channels, but we don't know what that value should be.
To demonstrate this, photograph a building. Suppose the sun is shining and the building casts a shadow. Place one gray card in the sunlight and another in the shadow. Take the photo, including the building and both cards. The pixel values from the cards will be different, because they are illuminated differently. Neither is "incorrect".
Quite likely the images of the cards will also have different hues because the one in the shadow is lit mostly by a blue sky.
As a further complication, the photographer probably aims for the maximum exposure that doesn't create clipping. (This is termed "exposing to the right".) If the photo includes just the building, the exposure can be quite large and the cards will have high pixel values. But if the photo also includes something bright, such as sky, the exposure must be reduced, and the pixel values for the cards will also reduce.
Re: White Balance Correction Using a Grey-card Reference
Posted: 2012-11-26T17:15:06-07:00
by snibgo
If white is taken as 100% and black as 1/60th of this, 100%/60 (=1.6667%), the geometric mean is sqrt (100 * 100/60) = 12.9099%.