White balance - color correction

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?".
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: White balance - color correction

Post by markmarques »

After some emails with Dave Coffin ( dcraw programmer) I have managed to understand some details...
As I wrote before , I do have the original ( RAW image) from X3F files by using "dcraw -d" ...


I have tried with NO sucess changing , adding , imposing , forcing the profile information with no success ... :(
I do have some partial success by using modulate in HSB colorspace and adding Saturation values plus some linear-stretch and gamma values ...

My problem is only with the REDdish tones , as shown in the previous posts ...
If I change the HUE the complete image is messed up except the REDdish part...

I have tried several matrixes with -recolor , with NO success ... :(

An idea would be to change the HUE in part of the image (or by using some fuzz color operator ? )

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

Re: White balance - color correction

Post by fmw42 »

-color-matrix can be programmed to change only red values or any combination of r,g,b values

I cannot say for sure if it will be what you need.

However, what did Dave Coffin say about WHY the colors are off so much? Are there any profiles with the raw image? Are they carried over to the JPG via dcraw by using some parameter that you have missed?

I have seen some images from RAW sources that have values for the color-matrix, that seem to help when used. I sent the following to some one recently regarding color correcting a JPG from a RAW image.


exiftool -s -ee -g1 -u -n -D test.jpg

...
- RedMatrixColumn : 0.43608 0.2225 0.01393
- GreenMatrixColumn : 0.38509 0.71689 0.09709
- BlueMatrixColumn : 0.14305 0.06061 0.71402


I put these into IM -color-matrix on the ORIGINAL JPG image and then applied -contrast-stretch 0.1%. Then optionally I added -gamma 1.5 to brighten non-linearly.


a1=0.43608
a2=0.2225
a3=0.01393
b1=0.38509
b2=0.71689
b3=0.01393
c1=0.14305
c2=0.06061
c3=0.71402
echo "$a1 $a2 $a3"
echo "$b1 $b2 $b3"
echo "$c1 $c2 $c3"
convert test.jpg -auto-level -color-matrix "
$a1 $a2 $a3 \
$b1 $b2 $b3 \
$c1 $c2 $c3 \
" test_colormatrix_3x3.jpg

THEN

convert test_colormatrix_3x3.jpg -contrast-stretch 0.1% test_colormatrix_3x3_cs0p1.jpg

THEN OPTIONALLY

convert test_colormatrix_3x3_cs0p1.jpg -gamma 1.5 test_colormatrix_3x3_cs0p1_g1p5.jpg
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: White balance - color correction

Post by markmarques »

Hi ... thanks for the fast update ....
Dave coffin did answered reporting that the FOVEON sensor does report some colour but still requires some complex (obfuscated inside X3F file ) matrix operations to get the correct colors ...

I will try your latest option and report as soon as I can ...


---------------------
Reporting sooner than I thought ....
But with NO more info...

After analysing the embedded JPEG thumbnail with exiftool ( ver 8.27)
the info present has no use ....
Lots of info regarind the camera model, firmware, whitebalance , date, etc etc
But NO info regarding the colormatrix ... :(

Tomorrow I will try some other stuff ...
Thanks for the support ... :)
Last edited by markmarques on 2010-08-04T16:14:40-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White balance - color correction

Post by fmw42 »

see http://www.imagemagick.org/script/comma ... lor-matrix

Think of the (basic 3x3) color-matrix as a linear transformation (gain or attenuation) between r,g,b channels

Horizontal row

input red, input green, input blue

Vertical column

output red
output green
output blue

So each entry is the gain if greater than 1 or attenuation if less than 1 between input and output channels.

r->r, g->r, b->r
r->g, g->g, b->g
r->b, g->b, b->b

If you want to only change red intensity, you would use

value,0,0
0,1,0
0,0,1

This would intensify or reduce the red, while holding the blue and green unchanged (and no mixing between channels)

But note that you can mix channels for example to change green to red if you want by using the corresponding matrix entry. Or yellow to red (by using the g->r and/or r->g possibly with negative values).

Unfortunately, IM does not allow negative values. But I have submitted a bug report on this.
Last edited by fmw42 on 2010-08-04T17:23:28-07:00, edited 3 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White balance - color correction

Post by fmw42 »

markmarques wrote:Hi ... thanks for the fast update ....
Dave coffin did answered reporting that the FOVEON sensor does report some colour but still requires some complex (obfuscated inside X3F file ) matrix operations to get the correct colors ...

I will try your latest option and report as soon as I can ...

How can you get or use these matrix values. This seems like the missing key.

I know nothing about X3F. That is your camera's raw format, correct? How can you get to the matrix data they need or use?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White balance - color correction

Post by fmw42 »

search google for "color correction matrix" and you get a lot of returns, for example:

http://www.imatest.com/docs/colormatrix.html
http://www.kodak.com/global/plugins/acr ... ensors.pdf
http://www.imageval.com/public/Products ... Matrix.pdf



Your camera maker should have a color correction matrix that is publicly available. Perhaps there are some repositories of such for various cameras. I don't know as I don't use RAW format.

PS. This article http://www.adobe.com/devnet/flash/artic ... ns_04.html has an interactive calculator that shows you the effects of changing the matrix values.

See also PixelBender for creating your own matrices at http://www.adobe.com/devnet/pixelbender/ and http://stackoverflow.com/questions/3295 ... ixelbender
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: White balance - color correction

Post by markmarques »

Hi ...
After some more digging in Internet I have found a partial color correction matrix for my previous problem

so I am using -recolor to solve my colour problems ...

http://sigmauserforum.com/forum/showthread.php?p=2776

6.8192 -4.2780 0.5284
-5.3869 9.4475 -3.3093
2.7067 -8.4825 8.2162

Although very similar to what I need I still have a another color problem ...

Image

almost all "blown highlights" become Magenta ...

I know that it is because of the increased saturation on the RAW file but the -S switch in dcraw does not work with the -D option ...

Do I have any other option to avoid the magenta problem in the highlights ?

One of the ayw I think is to cut some higher values in the histogram ...

Is there any way to "cut" a high value in the histogram ? a percentage perhaps ? like lets say 0.1% ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White balance - color correction

Post by fmw42 »

you can clip values in the historgram uniformly for all channels using -contrast-stretch. it allows fractional percents such as 0.1%. you can also do it separately on each channel by preceeding the command with -channel rgb. or you can do it on any one or two channels, such as -channels r or channels rg, etc.

see http://www.imagemagick.org/script/comma ... st-stretch
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: White balance - color correction

Post by markmarques »

in a previous post I saw this :
Unfortunately, IM does not allow negative values. But I have submitted a bug report on this.
Does this problem still being investigated ?
What is the behaviour of the negative values presented in the matrix ?
Is the signal being ignored ? Or is the value accepted as 0 ?

I am using the convert command with -recolor is this most updated nomeclature ? or is it "color-matrix" ?

Thanks for the help ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White balance - color correction

Post by fmw42 »

markmarques wrote:in a previous post I saw this :
Unfortunately, IM does not allow negative values. But I have submitted a bug report on this.
Does this problem still being investigated ?
What is the behaviour of the negative values presented in the matrix ?
Is the signal being ignored ? Or is the value accepted as 0 ?

I am using the convert command with -recolor is this most updated nomeclature ? or is it "color-matrix" ?

Thanks for the help ...
The issue will be fixed in the next release per the Bug forum reply. I think it was just an oversight of trapping on negative values and not allowing them as it probably was thought to be meaningless.

I think the behaviour of the negatives is to make complementary colors. See my post in the Bugs forum for examples at viewtopic.php?f=3&t=16787.

-recolor was renamed (somewhere around 6.6.1) to -color-matrix when it was modified to have more than a 3x3 matrix. See http://www.imagemagick.org/script/comma ... lor-matrix
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: White balance - color correction

Post by markmarques »

Just to report that after some trials (mannualy with color-matrix ) I have managed to achieve
a better color matrix (without the magenta highlights clipping) for the RAW SD14 ...

-- Matrix 8 correct
5.5 -3.5 0.95
-4.1 7.5 -2.1
2.7 -8.0 8.2

So now I only have to "learn" how to reduce the chroma noise ... :)

Thanks for the support ...
wiseman
Posts: 14
Joined: 2019-10-02T09:26:26-07:00
Authentication code: 1152

Re: White balance - color correction

Post by wiseman »

Is there a way we can read the color corrections within the dng files and apply to the imagemagick command while generating eps files from dng files?
Post Reply