2次元グラフの面積取得方法
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
2次元の座標データをもっていて
点に囲まれた座標の面積を求めたいです.
polyareaを使ってみましたが,形状が変わってしまいます. (sample.png)
左図:もとめたい形状
右図:plot した画像 → polyareaはこの形状の面積を求めている?
左図の形状を保った状態で,面積を取得する方法はありますか?
座標の分解能は保持したいです.
6 Kommentare
Akzeptierte Antwort
Hiroshi Iwamura
am 6 Apr. 2023
外枠いらなければ、最後のループも不要ですね。
I = imread("https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1345389/sample_c.png");
BW = imbinarize(I(:,:,2));
se = strel('disk',2);
BW2 = imclose(BW,se);
BW3 = imopen(BW2,se);
montage({I,BW,BW2,BW3})
stats = regionprops(BW3,'basic');
L = bwlabel(BW3);
T = struct2table(stats);
imshow(L,[],Colormap=jet)
idx = (T.Area > 100);
text(T.BoundingBox(idx,1),T.Centroid(idx,2),num2str(T.Area(idx)),'Color','white','FontSize',10);
fprintf('Total Area = %d\n',sum(T.Area(T.Area>10)))
2 Kommentare
Weitere Antworten (1)
Hiroshi Iwamura
am 4 Apr. 2023
Bearbeitet: Hiroshi Iwamura
am 4 Apr. 2023
なかなか正確に求めるのは難しく調整が必要になりますが、Image Processing Toolbox をお持ちであればモフォロジーを使う手はあります。Simulink (Computer Vision Toolbox) でやった方が色々と調整が簡単かもしれません。
I = imread("sample_c.png");
BW = imbinarize(I(:,:,2));
se = strel('disk',2);
BW2 = imclose(BW,se);
BW3 = imopen(BW2,se);
montage({I,BW,BW2,BW3})
stats = regionprops(BW3,'basic');
L = bwlabel(BW3);
T = struct2table(stats);
T = sortrows(T,'Area','descend');
% imshow(I)
imshow(L,[],Colormap=jet)
hold on
n = 1;
while T.Area(n) > 100
rectangle('Position',T.BoundingBox(n,:),EdgeColor=[1 0.2 0])
text(T.BoundingBox(n,1),T.Centroid(n,2),num2str(T.Area(n)),'Color','white','FontSize',10)
n = n + 1;
end
hold off
fprintf('Total Area = %d\n',sum(T.Area(T.Area>10)))
Siehe auch
Kategorien
Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!