0

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 May 24 '16 at 11:47
  • 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 May 24 '16 at 12:36
  • @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 May 24 '16 at 13:47
  • 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 May 25 '16 at 06:56
  • @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 May 25 '16 at 07:12
  • Just use normal difference instead of `absdiff`. Without knowing which language you are using, it is hard to give you a code example. @SimpleZurrie – Sunreef May 25 '16 at 07:45
  • I have tested them both, and it seems that in my case, the normal difference is best (SSIM comparison has been done before this color comparison, so images are already tested if near equal). Thanks to both @Miki @Sunreef! – SimpleZurrie May 26 '16 at 14:42

1 Answers1

2

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