How to calculate average intensity of image having some range?

5 vues (au cours des 30 derniers jours)
Prabhanjan More
Prabhanjan More le 25 Fév 2016
Réponse apportée : DGM le 30 Mai 2023
I want to calculate the average intensity of image having some range. That means i wanted to calculate average image intensity having value greater than 10, or find average intensity of image having intensity value from 10 to 85. How can i calculate? I had used mean2(grayImage) but it gives average intensity of whole image.

Réponses (1)

DGM
DGM le 30 Mai 2023
That's simple enough for a single channel image.
% inputs
inpict = imread('cameraman.tif'); % single-channel (I)
roirange = [10 85];
% create mask that describes the location of elements in the range
mask = inpict>=roirange(1) & inpict<=roirange(2);
% select and average
pagemean = mean(inpict(mask))
pagemean = 24.7511
... but if you want to deal wtih both grayscale and RGB images, maybe you want to deal with the problem pagewise.
% inputs
inpict = imread('peppers.png'); % 3-channel (RGB)
roirange = [10 85];
% create mask that describes the location of elements in the range
mask = inpict>=roirange(1) & inpict<=roirange(2);
% select and average pagewise
numchans = size(inpict,3);
pagemean = zeros(1,numchans);
for c = 1:numchans
pagemean(c) = mean(inpict(mask(:,:,c)),1);
end
pagemean
pagemean = 1×3
65.9711 97.6378 104.6979

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by