Refactored slightly and collected common code for determining the
largest region in a mask