Color Correction Matrix (linear vs RGB)

39 visualizzazioni (ultimi 30 giorni)
Ben Hendrickson
Ben Hendrickson il 26 Ago 2021
I've been playing with the new color correction functions in the Image Processing Toolbox, and I have a small conundrum. My solution is better when I apply gamma correction (lin2rgb() ) before calculating / applying the color correction matrix (derived from measureColor() ). The mean Delta_E ends up around half. I'm no color guru, but thought it was standard to keep the image linear when calculating / applying the matrix (the folks at Imatest are pretty emphatic about it https://www.imatest.com/docs/colormatrix/#linear ). Anyone have some insight why this is happening? Here's my code and the solution with then without gamma correction before the color correction. (Note: linearity of the demosaiced image, dJ has been verified by plotting gray chip signals against their mean spectral reflectances & calChartMeasure is basically the measureColor() function with some fiducial marking stuff added)
clear all;
close all;
calibrationIm = 's1500.raw';
% import the raw calibration image
J = rawImport(calibrationIm);
% demosaic the raw Bayer data
dJ = uint8(demosaicing_v2(double(J),'gradient'));
figure;
histogram(dJ)
saveas(gcf,'Histogram_Demosaicked.png')
figure;
imshow(dJ)
saveas(gcf,'Image_Demosicked.png')
% measure delta E
[dchart, dcolorTable, dccm] = calChartMeasure(dJ);
figure;
displayChart(dchart);
saveas(gcf,'Raw Chart Location.png')
figure;
displayColorPatch(dcolorTable);
saveas(gcf,'Raw Delta E values.png')
figure;
plotChromaticity(dcolorTable)
saveas(gcf,'Chromaticity Before Correction.png')
% apply gamma correction
gJ = lin2rgb(dJ);
figure;
imshow(gJ)
saveas(gcf,'Image_GammaCorrected.png')
[gchart, gcolorTable, gccm] = calChartMeasure(gJ);
figure;
displayChart(gchart);
saveas(gcf,'Gamma Chart Location.png')
figure;
displayColorPatch(gcolorTable);
saveas(gcf,'Gamma Delta E values.png')
figure;
plotChromaticity(gcolorTable)
saveas(gcf,'Chromaticity After Gamma.png')
% apply color correction matrix
ccJ = imapplymatrix(gccm(1:3,:)',gJ,gccm(4,:));
%ccJ = imapplymatrix(gccm(1:3,:)',gJ);
figure;
imshow(ccJ)
saveas(gcf,'Image_ColorCorrected.png')
[ccchart, cccolorTable, ccccm] = calChartMeasure(ccJ);
figure;
displayChart(ccchart);
saveas(gcf,'CCM Chart Location.png')
figure;
displayColorPatch(cccolorTable);
saveas(gcf,'CCM Delta E values.png')
figure;
plotChromaticity(cccolorTable)
saveas(gcf,'Chromaticity After CCM.png')
delE = mean(cccolorTable.Delta_E);
close all;
  3 Commenti
Image Analyst
Image Analyst il 27 Ago 2021
Where did you get the function calChartMeasure()?
Ben Hendrickson
Ben Hendrickson il 30 Ago 2021
It's nothing special. I made it out of some example code I found somewhere in the documentation.
function [chart, colorTable,ccm] = calChartMeasure(dJ)
% use fiducials
blackPoint = drawpoint;
whitePoint = drawpoint;
darkSkinPoint = drawpoint;
bluishGreenPoint = drawpoint;
cornerPoints = [blackPoint.Position;
whitePoint.Position;
darkSkinPoint.Position;
bluishGreenPoint.Position];
chart = colorChecker(dJ,'RegistrationPoints',cornerPoints);
% measure delta E
[colorTable,ccm] = measureColor(chart);

Accedi per commentare.

Risposte (3)

Ben Hendrickson
Ben Hendrickson il 3 Set 2021
So, I heard back from Mathworks, and the measureColor() function is indeed expecting an image in sRGB. Also, it's locked to assuming a 'd50' illuminant during the rgb2lab() stage of the process. I'm going to keep working on developing my own process (still shaky on how to build and optimize the transformation matrix) to improve on these results. But this specific matter is closed.

Image Analyst
Image Analyst il 3 Set 2021
Ben:
Yes, it uses sRGB and D50. I have my own color calibration process like you're trying to develop. Where I use D65, which I got from the published D50 values, then going back to XYZ, then to LAB D65
But it's kind of meaningless to talk about the delta E of a chart from a single image. It really doesn't matter and it's kind of arbitrary. For example let's say you took a photo and did what you're doing and got the delta Es. Now let's say you cut the exposure time in half and get delta Es on this darker image. Your delta Es will be bigger, maybe twice as big, roughly. However your actual object and illumination of it did not change at all.
And I don't even color correct images. I calibrate images. There is a difference. Color correction is basically getting a new RGB image from the old RGB image. In image analysis, who really cares about that? It's not needed unless you just wanted to visually correct the image for some purpose, like putting a bunch of photos take with different exposures on one screen. What I do is color calibration and this is converting the arbitrary RGB image into LAB color space. Then all the measurements for all the images are done on the LAB images. Then you can compute the delta E from one image to the other to see how much your actual object changed color. Of course you might need to develop an RGB-to-LAB function for each image if they were taken under different image capture conditions.
So comparing your image to some arbitrary sRGB image is really not needed or useful and could be misleading, depending on what you want to do.
By the way, I've been doing color science for decades and teach a class in it.
See attached presentation.
  1 Commento
Ben Hendrickson
Ben Hendrickson il 20 Apr 2022
Hi Image Analyst. Long time no chat. I've recently come back to this issue after a while off and it's still bugging me. Why does the Matlab version of this process (gamma => ccm) work? Everything I've read is explicit that deriving the matrix should be done on a linear image, which makes sense since it's doing linear algebra. Is it something to do with the fact that the gray chips on the Macbeth chart are themselves not physically linear (raw reflectance) but are perceptually linear (linear luminance in Lab space / linear RGB D50 reference values)?

Accedi per commentare.


Jeroen Van der poel
Jeroen Van der poel il 2 Giu 2022
Hey @image specialist. I have a question if you also calculate color matrixes professionally. We have xrite colorchart and used imatest but even though imatest gives us good results once we try to put the new matrix in dng file the results are off to a point that we simply want to hire someone. Is this something you do?

Prodotti


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by