In that case Remi is correct, within a small error. The image is discrete and so there will be a small difference between using all of the pixels and only those in the outline.
It's some (but not all) times the same, here is an example of the centroid for an object and its boundary, you can see that the values of Y are shifted a little bit.