imageopencvcolorshsvbgr

opencv report color differences between images


Assume an image A and an image B, where B is a modified copy of A with overall higher HSV-value and lower saturation. How can I report these differences using OpenCV?

Ex. output: hue 0, saturation -25, HSV-value +25.

I have already been able to convert the bgr-images to hsv-images and split these into the 3 channels. Would it be a good/correct idea to take the average of each channel of both images, and just output the difference of these averages? Or is there perhaps a better or already-included-in-opencv way? Thanks!


Solution

  • Answer was given in the comments, so credit goes to Miki and Sunreef.

    In case you want the results as in the example, a normal difference between the images will do (when Mats are in CV_8U format, convert to CV_32F using A.convertTo(A, CV_32F)):

    Mat diff = B - A;
    Scalar mean_diff = mean(diff);
    

    However, this can result in a 0 mean difference for very different images, so if the sign (positive or negative change) of the output is not relevant but the equality of the images is, use:

    Mat3b diff; absdiff(A,B, diff);
    Scalar mean_diff = mean(diff);