How to calculate average intensity of image having some range?
5 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
DGM
on 30 May 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))
... 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
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!