指定した領域で輝度値の平均と最大値を求める.
Show older comments
イメージにおいて,領域を指定してそこでの輝度値の平均・最大値を求めるにはどうすればよいでしょうか.
この領域とは,以下のプログラムを実行して得られた円形領域です.
data = ['42deg_cam1_ (12).jpg']; % ここでファイル名を変える
pic = imread(data);
gray = rgb2gray(pic);
bw = imbinarize(gray);
bw2 = bwareaopen(bw,30); % ノイズ除去,例として30ピクセル以下
[B,L] = bwboundaries(bw2,'noholes');
figure; % imshowはfigureの全画素を更新,hold onの効果なし,新しくfigureを立ち上げる
C = label2rgb(L,@jet,[.5 .5 .5]);
imshow(C);
hold on
for k = 1:length(B) % 境界線と色分け
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'w','LineWidth',2)
end
stats = regionprops(L,'Area','Centroid'); % ここから円形オブジェクトの検出コマンド
threshold = 0.80; % 閾値(円で1,他は1未満)
for k = 1:length(B)
boundary = B{k};
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
area = stats(k).Area;
metric = 4*pi*area/perimeter^2;
metric_string = sprintf('%2.2f',metric);
if metric > threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
end
text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
'FontSize',14,'FontWeight','bold')
end
2 Comments
Atsushi Ueno
on 1 Oct 2021
もう少し背景情報を加えて頂けるとより的確な回答に繋がります。
タグに記載された"sprintf", "bordaries"(?)との関連性も良く分かりません。
Egoshi
on 5 Oct 2021
Accepted Answer
More Answers (0)
Categories
Find more on イメージ算術 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!