Manually subtract mean value using OpenCV

1,446 views
Skip to first unread message

Daniel Sáez

unread,
Oct 29, 2015, 8:21:46 AM10/29/15
to Caffe Users
Hi,

I am using the dnn OpenCV module to deploy Caffe models, as explained in this blog post.

The module, however, doesn't support data transformations yet. I need to extract the mean value from my images so I though this would work:

cv::subtract(img, mean_value, img)

However, doing this doesn't result in the same feature vector that I get using Caffe directly or the python interface. Note that I do get the same result if I don't use mean values, i.e., if i don't use the data transformation in Caffe and I don't use subtract in OpenCV.

Any idea why this is happening? Is the mean value subtracted in a different way in Caffe?

Thanks in advance,

Daniel

Youssef Kashef

unread,
Oct 30, 2015, 5:45:51 AM10/30/15
to Caffe Users
I'd imagine the difference could be due to different data types.
Are you subtracting a scalar from a grayscale image?
If so, I would check the data type of the Mat object `img` as well as the `mean_value`. If they're of different types, implicit casting is going to take place.

I've noticed something similar when doing mean subtraction in python using numpy arrays and I had make sure to cast the mean subtracted image back to np.float (it was not the same as np.float32).

Nik Ahmad Akram Nz

unread,
Aug 1, 2016, 3:50:47 AM8/1/16
to Caffe Users
Hi, i exactly got in to this problem. have you come with the solution yet?
Message has been deleted

Jing Ye

unread,
Feb 10, 2017, 3:32:08 AM2/10/17
to Caffe Users
I have the same problem, have you solved it yet?
Reply all
Reply to author
Forward
0 new messages