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

18 ビュー (過去 30 日間)
daisuke shuugisono
daisuke shuugisono 2018 年 6 月 7 日
添付画像の円のそれぞれの平均輝度値を取得したいです。 どのような方法がありますか? ご回答よろしくお願いいたします。

採用された回答

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
daisuke shuugisono 2018 年 6 月 8 日
ご回答ありがとうございます。 参考にさせていただきます。

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!