Splitting a skeleton in a binary object to equal lengths!

3 次查看(过去 30 天)
Hello everyone,
I have a skeleton image obtained from running bwskel on a binary image. Here's couple of images as a sample:
I want find to specific number of points (for example 10 points) on these skeletons with equal distances from each other. Basically like splitting the skeleton to 10 equal parts.
I tried using bwconncomp to find the connected components in the the image and their pixel locations. But the locations are not in an order that I could use to split these to equal distances.
I would appreciate any kinds of suggestions!
Thank You

采纳的回答

Walter Roberson
Walter Roberson 2021-11-23
See https://www.mathworks.com/matlabcentral/fileexchange/34874-interparc "A common request is to interpolate a set of points at fixed distances along some curve in space (2 or more dimensions.) The user typically has a set of points along a curve, some of which are closely spaced, others not so close, and they wish to create a new set which is uniformly spaced along the same curve."
  7 个评论
Farshad Bolouri
Farshad Bolouri 2021-11-23
Well the results that I was showing were from interparc()!
But here are the results without using interparc() and just by using N'th point.
As you can see they basically look identical which is what I was interested in. I was trying to eliminate the step of interpolation for efficiency.
Now I am trying to see if I want to show the normals with respect to these points (blue circles), can I still work with the N'th point approach or do I need to interpolate.
This is what I currently have for the normal approximation:
skel_L = length(find(skel));
[endpointsX, endpointsY] = find( bwmorph(skel == 1, 'endpoints') );
trace = bwtraceboundary(skel, [endpointsX(1), endpointsY(1)],'N');
y = trace(1:skel_L,1);
x = trace(1:skel_L,2);
imshow(skel)
hold on;
norms = zeros(length(4: floor(skel_L/15) :skel_L-3),2);
i = 1;
for k=4: floor(skel_L/15) :skel_L-3
%plot(x(k),y(k),'bo')
% step 1 dv/dt
dx = (mean(x(k+1:k+3))-mean(x(k-3:k-1)));
dy =(mean(y(k+1:k+3))-mean(y(k-3:k-1)));
dvdt = [dx;dy];
% step2 rotate 90%
dvdtRot = [-dy ;dx];
% Step 3: Scale it to magnitude 1
% unit vector
dvdtRotNorm = dvdtRot/norm(dvdtRot);
scale=50;
pNorm = [x(k);y(k)]+scale*dvdtRotNorm;
%plot(pNorm(1),pNorm(2),'gs')
%line([x(k);pNorm(1)],[y(k);pNorm(2)])
norms(i,:) = pNorm;
i = i + 1;
end
k=4: floor(skel_L/15) :length(x)-3;
quiver(x(k),y(k), abs(x(k) - norms(:,1))*3, abs(y(k) - norms(:,2))*3, 'r' ,...
'LineWidth', 3, 'MaxHeadSize', 3)
I am not sure if this is a good approach to this task or not. In my opinion the normals don't look great but don't look bad either.
Do you have any suggestion on how I should approach this to possibly get better results?
PS: I attached the 2 mat files to this comment which are the two skeletons shown above.
Thank You
Jhe Mag
Jhe Mag 2022-6-29
Hello @Farshad Bolouri can I please ask for the code you used here?
I tried to run your code in the recent comment but it gives me error such as:
Index in position 1 exceeds array bounds (must not exceed 3).
y = trace(1:skel_L,1);
Hoping for help

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by