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

15 views (last 30 days)
daisuke shuugisono
daisuke shuugisono on 7 Jun 2018
添付画像の円のそれぞれの平均輝度値を取得したいです。 どのような方法がありますか? ご回答よろしくお願いいたします。

Accepted Answer

Akira Agata
Akira Agata on 7 Jun 2018
Edited: Akira Agata on 8 Jun 2018
例えば以下のようにすると、 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 Comment
daisuke shuugisono
daisuke shuugisono on 8 Jun 2018
ご回答ありがとうございます。 参考にさせていただきます。

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!