2次元グラフの面積取得方法

8 Ansichten (letzte 30 Tage)
H.O
H.O am 30 Mär. 2023
Kommentiert: H.O am 9 Apr. 2023
2次元の座標データをもっていて
点に囲まれた座標の面積を求めたいです.
polyareaを使ってみましたが,形状が変わってしまいます. (sample.png)
左図:もとめたい形状
右図:plot した画像 → polyareaはこの形状の面積を求めている?
左図の形状を保った状態で,面積を取得する方法はありますか?
座標の分解能は保持したいです.
  6 Kommentare
H.O
H.O am 2 Apr. 2023
Verschoben: Atsushi Ueno am 2 Apr. 2023
ありがとうございます.
実はアルファシェイプは最初に試したのですが,
各領域の面積や領域間との距離が小さいためか,アルファシェイプだと形状の変形が大きかったので,
ほかの方法を探していました.
申し訳ありません.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Hiroshi Iwamura
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)))
Total Area = 4289
  2 Kommentare
Hiroshi Iwamura
Hiroshi Iwamura am 8 Apr. 2023
なるほど
Computer Vision Toolbox もお持ちのようですね。

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Hiroshi Iwamura
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)))
Total Area = 4289
  1 Kommentar
H.O
H.O am 9 Apr. 2023
ありがとうございます。 必要なtoolboxも運良く所有していました。 挙げて頂いたスクリプトで実行、面積取得(pixel)できました。

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!