필터 지우기
필터 지우기

Color Correction Matrix (linear vs RGB)

조회 수: 27 (최근 30일)
Ben Hendrickson
Ben Hendrickson 2021년 8월 26일
답변: Jeroen Van der poel 2022년 6월 2일
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
Image Analyst
Image Analyst 2021년 8월 27일
Where did you get the function calChartMeasure()?
Ben Hendrickson
Ben Hendrickson 2021년 8월 30일
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);

댓글을 달려면 로그인하십시오.

답변 (3개)

Ben Hendrickson
Ben Hendrickson 2021년 9월 3일
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 2021년 9월 3일
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
Ben Hendrickson
Ben Hendrickson 2022년 4월 20일
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)?

댓글을 달려면 로그인하십시오.


Jeroen Van der poel
Jeroen Van der poel 2022년 6월 2일
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?

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by