I am needing to write a code that takes the rgb value of a reference square in an image, and color correct it to the orginal rgb value of the reference square. I will have various images with this reference square that will change colors depending on how the sunlight hits it, so I need to correct the whole image back to the original color. Is there a code that can be written to do this? Additionally, I mainly am focused on the blue values, but how will the change in values be stored?
Kshitij Singh answered .
2025-11-20
% Split test and reference image into component color channels. [rTest, gTest, bTest] = imsplit(testImage); [rRef, gRef, bRef] = imsplit(refImage); % Assign mean color from ref image to test image, but only in the square region. rTest(testSquaremask) = mean(rRef(refSquareMask)); gTest(testSquaremask) = mean(gRef(refSquareMask)); bTest(testSquaremask) = mean(bRef(refSquareMask)); % Rebuild test image from component color channels. testImage = cat(3, rtest, gTest, bTest);