mitk::ImageStatisticsCalculator has an operation mode in which it takes a (binary) image mask as second input and calculates statistics of the gray-value input image only for those pixels which are not masked out in the image mask.
Currently, the image mask is assumed to be of the same dimensions (origin, spacing, index, size) as the input image. It would be more practical if also image masks smaller than (but fully inside) the input image could be used. Also checks for correct dimensions of the mask should be added.