Splitting a skeleton in a binary object to equal lengths!
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
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
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
Hello Walter!
Thank You for your answer, I have actually tried this function before. I was wondering if this is possible without interpolation.
But even with interparc() I think I am not understanding something correctly. When the points are sorted with respect to 'x' this is what I get:
skel = bwskel(worm); %worm is the original image
[y, x] = find(skel);
pt = interparc(100,x,y,'spline');
plot(x,y,'r*',pt(:,1),pt(:,2),'b-o')

And when I sort with respect to 'y' values:
skel = bwskel(worm); %worm is the original image
[y, x] = find(skel);
[sortedY, sortIndex] = sort(y)
sortedX = x(sortIndex)
pt = interparc(100,sortedX,sortedY,'spline');
plot(x,y,'r*',pt(:,1),pt(:,2),'b-o')

It seems like that the order of 'x' and 'y' values matter. Could you help me on how to fix this problem?
Thank You
You need to get the worm sorted. Using find() does not do that. It has no concept of what pixel is next to any other pixel. It just goes down rows and moves over column-by-column from left to right. You need to use regionprops(), which I think will sort it right, or at least better, for you. Try
props = regionprops(mask, 'PixelList', 'PixelIdxList');
props.PixelList is the list of (x,y) coordinates, hopefully going from one end to the other and not going column by column which is what find() does.
props.PixelIdxList is the linear Index of the pixel in the original mask image.
Attach 'skel' in a .mat file if you need more help.
save('answers.mat', 'skel');
The bwtraceboundary() function worked perfectly in this case! Here are the results for interpolation:


Again, thank you!
Did you end up using interparc() or did you just take every N'th point from the boundary trace?
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
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개)
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
