画像から座標を取得する.

조회 수: 26 (최근 30일)
Egoshi
Egoshi 2021년 10월 5일
data = ['42deg_cam1_ (1).jpg']; % ここでファイル名を変える
pic = imread(data);
imshow(pic);
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
これを実行して得られた円形オブジェクトの中心のピクセル座標を,別のfigureに表示させることは可能でしょうか.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!