# How to find Summary Statistics of Image in Matlab

7 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
im=imread('MOD16A2.A2002001.h24v05.006.2017075173934_ET.tif');
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?
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

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.
originalImage = imread('MOD16A2.A2002001.h24v05.006.2017075173934_ET.tif');
% 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;
maskedImage = originalImage .* uint16(mask);
subplot(2, 2, 3);
imshow(maskedImage, []);
meanGrayLevel = mean(originalImage(mask), 'omitnan')
caption = sprintf('Mean = %f', meanGrayLevel)
title(caption);
##### 7 CommentsShow 5 older commentsHide 5 older comments
Muhammad Usman Saleem on 31 Dec 2021
@Image Analyst Sir, Many thanks for your kind reply. I definately accept your answer as it satisfy me.
One more task I needed, I want to skip pixel values ranging 32761 to 32767 and 65536 while calculating mean of pixel values falling within my shapefile domain. Will you please edit your kind answer so that I skip pixel values ranging from 32761 to 32767 ( by MODIS documentation this range contains buildup landcover) and 65536 (Background), I not need these pixel values in my Mean value. Please modify your kind code.
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;
originalImage = imread('MOD16A2.A2002001.h24v05.006.2017075173934_ET.tif');
% 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.
mask = ~pixelsToExclude;
subplot(2, 3, 5);
imshow(mask, [])
title('Pixels to Include');
maskedImage = originalImage .* uint16(mask);
subplot(2, 3, 6);
imshow(maskedImage, []);
meanGrayLevel = mean(originalImage(mask), 'omitnan')
caption = sprintf('Mean = %f', meanGrayLevel)
title(caption);

Sign in to comment.

### Categories

Find more on Image Arithmetic in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!