regionprops関数の応用について。
Show older comments
beboundaries関数の後にregionprops関数を使用し、画像の楕円に沿わせた曲線の長さを測りたいのですが、プログラムがうまく行きません。
regionprops関数の例が載っているページを確認しましたが、自分のプログラムと合わせることができません。
プログラムは以下の通りです。
%%画像入力
kaki_img=imread('box_dark.jpg'); %画像読み込み
%kakiimg=imcrop(kakiimg)
figure(2)
imshow(kaki_img,'Border','tight','InitialMagnification','fit');
%%画像全体のセグメンテーション
kaki_red=kaki_img(:,:,1); %画像のセグメンテーション(赤要素検出)
figure(3)
imshow(kaki_red,'Border','tight','InitialMagnification','fit');
%%画像の二値化
kaki_th=kaki_red>180;
figure(4)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
%%二値化画像の穴埋め
kaki_th=imfill(kaki_th,'holes');
figure(5)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
%%二値化画像のクリーンナップ(周囲の白を除去)
cc1=bwconncomp(kaki_th);
main1=regionprops(cc1,'Area');
A=[main1. Area];
[~,biggest]=max(A);
kaki_th(labelmatrix(cc1)~=biggest)=0; %最大の塊となっている1の要素以外の1の要素を0にする
figure(6)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
%%牡蠣の二値化画像の外周に色付け
BW=imbinarize(I);
%%Detec boundarries
B=bwboundaries(kaki_th,'noholes');
figure(7)
imshow(BW)
hold on
for kk=1:numel(B)
%%'c'で色を固定
plot(B{kk}(:,2),B{kk}(:,1),'c','LineWidth',2)
end
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
