In Matlab i used the following code:
% colour correction on brightest pixel
I = image;
S = sum(I,3); % sum all colour channels
[~,idx] = max(S(:)); % find brightest pixel
[x, y] = ind2sub(size(S),idx); % find coordinates of brightest pixel
image = chromadapt(image,impixel(image,y,x)); % apply colour correction
figure, imshow(image);
Now i want to use this in opencv c++ but i'm getting stuck.
The input image is this image (in matlab): https://imgur.com/a/63kDF6Y
The output image is this image (in matlab): https://imgur.com/a/waqV7zv
I want to get the same results using opencv c++, i tried the following code but i'm getting stuck.
// chroma correction
Mat colorChannels[3];
split(image, colorChannels);
int avgMax, diffR, diffG, diffB {};
uchar maxPixR, maxPixG, maxPixB;
maxPixR = colorChannels[0].at<uchar>(loc);
maxPixG = colorChannels[1].at<uchar>(loc);
maxPixB = colorChannels[2].at<uchar>(loc);
avgMax = maxPixG;
diffR = maxPixR - avgMax;
diffG = maxPixG - avgMax;
diffB = maxPixB - avgMax;
colorChannels[0] -= diffR;
colorChannels[1] -= diffG;
colorChannels[2] -= diffB;
merge(colorChannels, 3, image);
The output of this code: https://imgur.com/a/zkykEJO The image is too blue and i'm not getting the result from Matlab.
Can someone help me with this? Already thanks for it.
Aucun commentaire:
Enregistrer un commentaire