指定した領域で輝度値の平均と最大値を求める.
이전 댓글 표시
イメージにおいて,領域を指定してそこでの輝度値の平均・最大値を求めるにはどうすればよいでしょうか.
この領域とは,以下のプログラムを実行して得られた円形領域です.
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
Atsushi Ueno
2021년 10월 1일
もう少し背景情報を加えて頂けるとより的確な回答に繋がります。
タグに記載された"sprintf", "bordaries"(?)との関連性も良く分かりません。
Egoshi
2021년 10월 5일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 イメージ算術에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!