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

조회 수: 18 (최근 30일)
daisuke shuugisono
daisuke shuugisono 2018년 6월 7일
댓글: daisuke shuugisono 2018년 6월 8일
添付画像の円のそれぞれの平均輝度値を取得したいです。 どのような方法がありますか? ご回答よろしくお願いいたします。

채택된 답변

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!