2値化された画像の線状物体長さの推定方法に関しまして
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Wired_Arms
le 28 Nov 2019
Commenté : Wired_Arms
le 30 Nov 2019
2値化された画像の線状物体の長さを推定する方法について質問があります。画像は射影変換が適用されており、実際の物体長さとピクセル単位長さ[mm / px]は既知です。問題は形状によって推定誤差(30〜40mm)が生じる点です。 アドバイスお願い致します。

%% Searching endpoints
% input image_size :350×540(logical)
idx_skel = Image;% idx_skel : image applied bwskel
endpoints = zeros(2,2);
for i = 2:349
for j = 2:539
l_sum = idx_skel(i-1,j-1) + idx_skel(i-1,j) + idx_skel(i-1,j+1) + idx_skel(i,j-1) + idx_skel(i,j+1) + idx_skel(i+1,j-1) + idx_skel(i+1,j) + idx_skel(i+1,j+1);
if idx_skel(i,j) == 1 && l_sum == 1 && endpoints(1,1) == 0
endpoints(1,1) = i;
endpoints(1,2) = j;
elseif idx_skel(i,j) == 1 && l_sum == 1 && endpoints(1,1) ~= 0
endpoints(2,1) = i;
endpoints(2,2) = j;
end
end
end
%% Calculating total length
x_px =2;% unit-length of columns [mm/px]
y_px =2;% unit-length of rows [mm/px]
num_cols = abs(endpoints(1,2)-endpoints(2,2)) +1;
one = zeros(num_cols,2);
for i = 1:num_cols
one(i,1) = endpoints(1,2) + (i-1);
end
for i = endpoints(1,2):endpoints(2,2)% find '1' index every column
K = find(idx_skel(:,i),1);
one(i +1 - endpoints(1,2),2) = K;
end
L =0;
for i = 1:num_cols-1
L_sum = sqrt(((one(i+1,1) - one(i,1))*x_px).^2 + ((one(i+1,2) - one(i,2))*y_px).^2);% approximate to staraight line
L = L + L_sum;% L : total length
end
0 commentaires
Réponse acceptée
Shunichi Kusano
le 28 Nov 2019
こんにちは。
関数を使って次のようにやってみました。
3つの画像で線の長さは本当は一緒なんでしょうか。
それぞれ試してみたところ次のようになりました(単位:px)。
image1 - 396.6792
image2 - 394.6420
image3 - 395.8294
function length = lineLength(image)
% 白画素の位置を取得
stats = regionprops(image, "PixelList");
p = [stats.PixelList];
% 各画素の座標値がサンプリング点座標である
% これは離散値(整数)なのでそのまま点間の距離を測ると実際より長くなる。なので移動平均を使って滑らか(実数)にする
p_smooth = movmean(p, 5, 1);
% 各点間の距離を出す
distances = sqrt(diff(p_smooth(:,1)).^2 + diff(p_smooth(:,2)).^2);
% 足し合わせて線の長さの近似値を得る
length = sum(distances);
end
ちなみにbwmorphという関数の中でendpointをとってくることが出来ますし、find関数でもfor文の中でやられているようなことは高速にできるかと思います。いろいろな関数があるのでうまく使って楽しちゃってください。
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Preview and Device Configuration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!