MATLAB: Finding the mean pixel value in a unit8 matrix

unit8

Im trying to find the mean pixel value in a unit8 matrix but when i try summing the pixel values together before dividing by the number of pixels, it doesn't go past 255. e.g 172+176 = 255. Is there a way i can convert the unit8 matrix to a double matrix without it suppressing my values?

Best Answer

There is no unit8. There is a uint8 however. But if the sum of integers goes past intmax('uint8'), which is 255, it clips to 255. The solution is to cast your numbers to double before summing with the "+" operator, or you can use sum() which does that internally.