To find out where the maximum of the masked image is:
IdxImg = reshape(1:numel(img), size(img));
masked_image_idx = IdxImg(mask1);
[max_value, max_idx] = max(img(mask1));
index_of_max = masked_image_idx(max_idx);
[MaxRow, MaxColumn, MaxPage] = ind2sub(size(img), index_of_max);
This works by creating an indexing image the same size as the original image, but containing 1, 2, 3, ... all the way up to the maximum array element number. Then you extract the portion of the indexing image under the mask, to get a vector of the element numbers covered by the mask. Then take the max() of the masked image, getting out the (linear) index of the maximum element. Use the linear index of the maximum element to index the vector of indexing array elements selected by the max, getting out the linear index of the array element in the original image. Then convert the linear index back to subscripts if necessary.