# How to find Summary Statistics of Image in Matlab

조회 수: 12 (최근 30일)
Muhammad Usman Saleem 2021년 12월 18일
댓글: Image Analyst 2021년 12월 31일
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 2021년 12월 19일
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);
##### 댓글 수: 7이전 댓글 5개 표시이전 댓글 5개 숨기기
Muhammad Usman Saleem 2021년 12월 31일
@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 2021년 12월 31일
@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);

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Image Arithmetic에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by