# How to find Summary Statistics of Image in Matlab

12 views (last 30 days)
Muhammad Usman Saleem on 18 Dec 2021
Commented: Image Analyst on 31 Dec 2021
I've MODIS satellite raster (tiff image) and this raster is of evapotrainspiration (ET) dataset collected by this satellite. I want to find mean ET over my study area, however, this mean value of the raster is different from the mean value of the ET calculated in ESRI software e.g., ArcGIS. I am using this simple code
imm=im*0.1 %multipling scale factor according to MODIS documentation
imm(imm == 65535) = nan; %datavalues outside the study area as nan
nemean=mean2(imm)
The mean value comes:
nemean =
4.9621
But the actual mean value of ET is
337.422222
i'm sharing ET image with this question. Why mean value of raster comes different in matlab? I think, I'm doing some mistake please correct?

Image Analyst on 19 Dec 2021
Perhaps you have the wrong image. The images has values only up to a gray level of 71, if you don't count all those values that are saturated at 65535. And the mean is 20.621096. How are you defining your "Study area"? There are no values around 337 or 10 times that in the image.
% imm=originalImage*0.1 %multipling scale factor according to MODIS documentation
subplot(2, 2, 1);
imshow(originalImage, [])
title('Original 16 bit image');
subplot(2, 2, 2);
[counts, edges] = histcounts(originalImage, 65536);
% Suppress huge spikes at 0 and 65535
counts(1) = 0;
counts(end) = 0;
% Find last non-zero bin
lastBin = find(counts > 0, 1, 'last')
bar(edges(1:lastBin), counts(1:lastBin))
grid on;
title('Histogram')
% Change 65535 to 0.
mask = originalImage < 65535;
subplot(2, 2, 3);
meanGrayLevel = mean(originalImage(mask), 'omitnan')
caption = sprintf('Mean = %f', meanGrayLevel)
title(caption);
Image Analyst on 31 Dec 2021
@Muhammad Usman Saleem, Thanks for your (future) acceptance. Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
% imm=originalImage*0.1 %multipling scale factor according to MODIS documentation
subplot(2, 3, 1);
imshow(originalImage, [])
impixelinfo;
title('Original 16 bit image');
subplot(2, 3, 2:3);
[counts, edges] = histcounts(originalImage, 65536);
% Suppress huge spikes at 0 and 65535
counts(1) = 0;
counts(end) = 0;
% Find last non-zero bin
lastBin = find(counts > 0, 1, 'last')
bar(edges(1:lastBin), counts(1:lastBin))
grid on;
title('Histogram')
% "I want to skip pixel values ranging 32761 to 32767 and 65536"
% There is no 65536 so I'll assume you mean 65535.
pixelsToExclude = (originalImage >= 32761 & originalImage <= 32767) | (originalImage >= 65535);
subplot(2, 3, 4);
imshow(pixelsToExclude, [])
title('Pixels to Exclude');
% The pixels to consider is just the inverse of the pixels we want to exclude.
subplot(2, 3, 5);
title('Pixels to Include');
subplot(2, 3, 6);
meanGrayLevel = mean(originalImage(mask), 'omitnan')
caption = sprintf('Mean = %f', meanGrayLevel)
title(caption);

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by