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

26 views (last 30 days)
Egoshi
Egoshi on 5 Oct 2021
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に表示させることは可能でしょうか.

Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!