0
votes

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!

1
You don't need to split... e.g.: Mat3b diff; absdiff(A,B, diff); Scalar mean_diff = mean(diff); will give you the differences of the mean in the 3 channels separately.Miki
I'm not sure that absdiff is exactly what should be used here. You lose the sign of the differences by doing that. Maybe just writing Mat diff = A - B; is enough (if you are using C++ and CV_8U matrices, you should convert them to CV_32F before to be able to store negative values)Sunreef
@Sunreed you you want the mean of the differences, you need to use the absolute value. Otherwise you can get 0 mean difference for very different images.Miki
thanks! this seems to do the job. If you want to write it as an answer I can accept it. Do you perhaps know a way to achieve a result like @Sunreef (sign included), but still have the same correctness?SimpleZurrie
@Miki It seems to me that the original question doesn't rule out the possibility of having a 0 mean difference, even a negative mean difference, if I judge by the example output proposed.Sunreef

1 Answers

2
votes

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);