画像からある範囲の平均輝度値を取得する方法

15 次查看(过去 30 天)
daisuke shuugisono
添付画像の円のそれぞれの平均輝度値を取得したいです。 どのような方法がありますか? ご回答よろしくお願いいたします。

采纳的回答

Akira Agata
Akira Agata 2018-6-7
编辑:Akira Agata 2018-6-8
例えば以下のようにすると、 regionprops 関数でそれぞれの円領域に含まれるピクセルの位置情報を取得したうえで、その情報を使って円ごとの輝度の平均値を算出することができます。
% Read image and convert to gray-scale
I = imread('sample_circles.bmp');
Igray = rgb2gray(I);
% Obtain regions of interest
BW = imbinarize(Igray);
BW = imclearborder(BW);
se = strel('disk',1);
BW = imclose(BW,se);
% Obtain information for each region
s = regionprops('table',BW,{'Centroid','BoundingBox','PixelIdxList'});
% Calculate average luminance for each region
avLuminance = zeros(height(s),1);
for kk = 1:height(s)
avLuminance(kk) = mean(Igray(s.PixelIdxList{kk}));
end
% Show the result
figure
imshow(Igray)
hold on
for kk = 1:height(s)
rectangle('Position', s.BoundingBox(kk,:),'EdgeColor', 'c');
text(s.Centroid(kk,1),s.Centroid(kk,2),...
sprintf('%.1f',avLuminance(kk)),...
'FontWeight', 'bold',...
'HorizontalAlignment','center',...
'Color', 'c')
end
  1 个评论
daisuke shuugisono
ご回答ありがとうございます。 参考にさせていただきます。

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!