如何使用Mat-Lab计算图像中特定区域的平均值?
例如,如果我有一个强度图像,其面积更大,并且我想知道强度的平均值是多少,我该如何计算?
我想我可以使用“impixelinfo”命令找到下车区域的坐标。
如果还有另一种更有效的查找坐标的方法,我也将很高兴知道。
我知道坐标后,如何计算图像部分的平均值?
最佳答案
您可以在Matlab中使用imroi
类型的函数之一,例如imfreehand
I = imread('cameraman.tif');
h = imshow(I);
e = imfreehand;
% now select area on image - do not close image
% this makes a mask from the area you just drew
BW = createMask(e);
% this takes the mean of pixel values in that area
I_mean = mean(I(BW));
另外,请考虑使用
regionprops
,特别是如果图像中可能有多个以上功能之一时。在这里,我要在图像中找到一些高于阈值强度的点,然后使用imdilate
在这些点的每一个周围选择一个较小的区域(假定阈值以上的点被很好地分开了,可能不是这种情况-如果它们是如果距离太近,则会将其合并为一个区域)。se = strel('disk',5);
BW = imdilate(I>thresh,se);
s = regionprops(BW, I, 'MeanIntensity');
关于matlab - 计算部分图像的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18681661/