2値化された画像の線状物体長さの推定方法に関しまして
显示 更早的评论
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Image Preview and Device Configuration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!