Try this instead, which will select only the pixels in image dictated by the mask:
masked_image = image.*(mask > 0);
masked_image_pixels = image(mask > 0);
Note that mask should really be a logical array, not a uint8 array, which is what (mask > 0) is taking care of for you.
In your original code, the issue is that you are using a uint8 mask matrix to multiply element-by-element with the image matrix. This means doing the following:
image .* mask
(value from the image matrix) x (255 or 0 from the "binary" uint8 mask matrix)
which would explain the large numbers.
Best Answer