Home > database >  How color Calibrate image (jpg/png) with Reference Color in C# using colormatrix
How color Calibrate image (jpg/png) with Reference Color in C# using colormatrix

Time:03-14

I have image which has object for reference. e.g. Rectangle at a particular position.

For (Rectnangle) we already have it's ideal/reference color values e.g. R=255, G=255, B= 255.

Mean RGB of Reactangle is something different e.g. R=200,G=200,B=200.

So there is R=55,G=55,B=55 deviation from ideal/reference color.

How do use color-matrix to fill this gap of color so that I will get calibrated image ?

Please suggest, if any better approch rather than this.

CodePudding user response:

you would calculate the quotient of the two colors, i.e. 255 / 200, and input this in the diagonal values in the color matrix. i.e.

var cr = referenceRed/ actualRed;
...
float[][] colorMatrixElements = { 
   new float[] {cr,  0,  0,  0, 0},        // red scaling factor
   new float[] {0,  cg,  0,  0, 0},        // green scaling factor
   new float[] {0,   0,  cb, 0, 0},        // blue scaling factor
   new float[] {0,   0,  0,  1, 0},        // alpha scaling factor of 1
   new float[] {0,   0,  0,  0, 1}};   

  • Related