Color Correcting a whole image using RGB values

3 views (last 30 days)
I asked a question earlier about color correcting, but can't figure out how to correctly get the code to work.
This is the code I've written from scratch. It works to display the avg RGB values from the ROI, but I need to be able to color correct the image first to a certain RGB value.
I attached the images this time with my reference panel in it, which I think imread should be corrected to I=imread('practiceimage1.png') right?
The original RGB value of the panel is 180 183 182 so I need to correct the whole image i guess using the change in RGB from each image to the original rgb of 180 183 182.
Thanks
%Code modified june 12
% Load pictures into Matlab
I=imread('matlabtestimage.jpg'); %reads image and store in array I
imshow(I);
title('Image1') %title image
%color corerct
%create region of interest within each picture
h=drawrectangle('Position',[852,670,756,376],'StripeColor','b');
mask=createMask(h);
[row,col]=find(mask); %find rows and columns for collecting rgb data
%collect rgb values from region of interest
RGBpixels=impixel(I,col,row);
pos=h.Position;
%calculate average red, green, blue values in the region of interest
avgrgb=mean(RGBpixels);
fprintf('The average Red,Green, and Blue values of the ROI are %6.3f, %6.3f, and %6.3f\n',avgrgb)

Answers (1)

Image Analyst
Image Analyst on 13 Jun 2023
One way you might do it is to draw the rectangle in both images in the same location. Then figure out the mean difference in each color channel. Then add or subtract those 3 means from the proper color channel to make the one image match the other image (at least the means in the rectangles will match).

Community Treasure Hunt

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

Start Hunting!