Splitting a skeleton in a binary object to equal lengths!

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Nov. de 2021
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 comentarios
Farshad Bolouri
Farshad Bolouri el 23 de Nov. de 2021
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 el 29 de Jun. de 2022
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

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by