イメージの長手方向と短手方向の長さを算出するプログラムについてです
Show older comments
以下のコードで画像に示しているような部分の長さを検出したいと考えています.
赤が長手,size_Longで,緑が短手,size_shortです.

検出はできており,算出はしてくれるのですが,実際の値と異なっており,困っています.
下にあるのがma_L_4_sita.jpgです
%画像入力
kaki_img=imread('ma_L_4_sita.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>63;
figure(4)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
%%二値化画像の穴埋め
kaki_th=imfill(kaki_th,'holes');
figure(5)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
%%二値化画像のクリーンナップ(周囲の白を除去)
kaki_th=bwareafilt(kaki_th,1);
figure(6)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
%%牡蠣の二値化画像の外周に色付け
% BW=imbinarize(I);
BW = kaki_th;
%%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
stats_x=regionprops('table',BW,'Perimeter');
title(sprintf('boundary length is %d',stats_x.Perimeter))
%%外周の大きさをスケーリング
size1=stats_x.Perimeter*0.1003;
%%長手,短手の最長距離算出
stats_2 = regionprops(BW, 'MajorAxisLength', 'MinorAxisLength');
%figure(8)
%imshow(stats_2);
%%長手,短手の最長距離のスケーリング
size_Long=stats_2.MajorAxisLength*0.1003;
size_Short=stats_2.MinorAxisLength*0.1003;

size_Longは297,size_shortは174と自分が実行した際は算出されました
実際にはsize_Longは105,size_shortは70程度の値が理想です
よろしくお願いします.
Accepted Answer
More Answers (0)
Categories
Find more on ライティング、透明度、およびシェーディング 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!