BUG: When computing the mask from the average image, the mask was computed on the padded images, and therefore the mask size did not match the average image size.