フェレ径(イメージ領域)の可視化

19 views (last 30 days)
彩華 伊佐
彩華 伊佐 on 3 Nov 2022
Commented: 彩華 伊佐 on 4 Nov 2022
二値化画像から取得したフェレ径について、どの部分を計算しているのか確認したいです。
二値化画像に重ね合わせる形で、フェレ径の線分を表示させる方法を教えていただきたいです。
コードは以下の通りです。
I = imread("image.jpg");
% 2値化
level = graythresh (I);
BW = imbinarize(I,level);
BW1 = imfill(BW,'holes'); % オブジェクトの塗り潰し
Label = bwlabel(BW1,4); % ラベリング処理
prop = regionprops(Label,'MaxferetProperties'); % フェレ径情報の取得

Accepted Answer

Kojiro Saito
Kojiro Saito on 4 Nov 2022
bwferetのドキュメントが役立つと思います。
フェレ径を求めた後、imshowで画像を表示した後、imdistlinelineを使って線を重ね書きできます。
同じ画像ファイルがないので、ここではtoyobjects.pngを使った例を提示します。
imdistlineの場合:線と距離が表示されます
I = imread("toyobjects.png");
bw = imbinarize(I,'adaptive');
bw = bwareafilt(bw,4);
bw = imfill(bw,'holes');
prop = regionprops('table', bw,'MaxferetProperties'); % フェレ径情報の取得
feretMax = prop.MaxFeretCoordinates;
feretMaxDiameter = prop.MaxFeretDiameter;
% フェレ径の線分の表示 (imdistlineの場合)
imshow(I);
axis = gca;
for n = 1:height(feretMax)
xmin = [feretMax{n}(1,1) feretMax{n}(2,1)];
ymin = [feretMax{n}(1,2) feretMax{n}(2,2)];
imdistline(axis,xmin,ymin);
end
lineの場合:線のみ表示されます
I = imread("toyobjects.png");
bw = imbinarize(I,'adaptive');
bw = bwareafilt(bw,4);
bw = imfill(bw,'holes');
prop = regionprops('table', bw,'MaxferetProperties'); % フェレ径情報の取得
feretMax = prop.MaxFeretCoordinates;
feretMaxDiameter = prop.MaxFeretDiameter;
% フェレ径の線分の表示 (lineの場合)
imshow(I);
axis = gca;
for n = 1:height(feretMax)
xmin = [feretMax{n}(1,1) feretMax{n}(2,1)];
ymin = [feretMax{n}(1,2) feretMax{n}(2,2)];
line(axis, xmin, ymin)
end
  1 Comment
彩華 伊佐
彩華 伊佐 on 4 Nov 2022
表示させることができました。ありがとうございます。

Sign in to comment.

More Answers (0)

Categories

Find more on イメージ in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!