how to calculate width from center line in binary image ?
2 次查看(过去 30 天)
显示 更早的评论
Hello !
my goal is to find the location of my object which has the smallest width.
I did the skeletonization and then I tried to apply bwdist on my image. Then I multiplied the 2 images. But how do I know which is the location with the smallest width ? (because I need to mark and identify this location).
Thank you
close all;
clear all;
clc;
folder = "C:\Users\larle\OneDrive\Documents\Image_chromosomes\testing_matlab2\resultat";
baseFileName = "entite4.png";
fullFileName = fullfile(folder, baseFileName);
im = imread(fullFileName);
im = imsharpen(im);%accentue nettete avec masquage flou
im = medfilt2(im);%filtre median en 2D (reduction de bruits)
thresholdValue=220;
%binarisation
binaryImage = im < thresholdValue;
%skel without extremum
skel= bwmorph(binaryImage,'skel',Inf);
B = bwmorph(skel, 'branchpoints');
E = bwmorph(skel, 'endpoints');
[y,x] = find(E);
B_loc = find(B);
Dmask = false(size(skel));
for k = 1:numel(x)
D = bwdistgeodesic(skel,x(k),y(k));
distanceToBranchPt = min(D(B_loc));
Dmask(D < distanceToBranchPt) =true;
end
skelD = skel - Dmask;
figure(2)
imshow(skelD)
hold all;
edtImage = bwdist(binaryImage);
centerlineImage = double(skelD) .* edtImage;
figure(5)
imshow(centerlineImage)
meanRadius = mean(centerlineImage(skelD))
figure(6)
imshow(meanRadius)
1 个评论
Adam Danz
2021-3-16
I only see 1 object in your image. Is there supposed to be multiple objects? If not, I don't know what to goal is, "to find the object with the smallest width".
回答(2 个)
Image Analyst
2021-3-16
You can use min() to find the min value of the centerlineImage that's not zero. Then use find to find the row and column
minValue = min(centerlineImage(centerlineImage > 0))
[rowOfMin, columnOfMin] = find(centerlineImage == minValue)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!