Finding distance between endpoints of image segment: PixelList vs 'endpoints'
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ryan
el 22 de Jun. de 2012
Comentada: Jay Cheng
el 13 de Mzo. de 2015
New Code:
%%Calculate Tortuosity
disp('Calculating tortuosity of large segments');
V = thin8-imdilate(crosslinks,strel('disk',2));
V(V<=0) = 0; V(V>0) = 1; % return to binary
V = bwareaopen(V,3); % get rid of small segments
[K n] = bwlabel(V,8);
props = regionprops(K,'Perimeter');
tort = zeros(1,n);
endpts = bwmorph(V,'endpoints');
endpts_labeled = immultiply(K,endpts);
for m = 1:n
[rows,cols] = find(endpts_labeled==m);
if numel(rows) ~= 2
tort(m) = NaN;
else
p1 = [rows(1),cols(1)];
p2 = [rows(2),cols(2)];
d = sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2);
c = props(m,1).Perimeter/2;
tort(m) = c/d;
end
end
tort(isnan(tort)) = [];
tort_avg = mean(tort);
tort_std = std(tort);
Original Post:
I am working to find the tortuosity of about 500-1000 segments like this one:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/147599/image.png)
They are randomly spaced throughout a larger image and have varying lengths and orientation. I am using a simple definition of tortuosity (tort = distance between endpoints/length of curve). I am getting an accurate reading of the curve length verified via Matlab Blog Post, but I am not sure if I am getting an accurate distance between the endpoints.
I am trying two different methods (using PixelList and the slower method of Endpoints), but neither method is giving me the exact number expected for some of the segments I spot checked and I was wondering which is the more accurate method for determining the euclidean distance of the segments endpoints. My code is as follows:
0 comentarios
Respuesta aceptada
Image Analyst
el 22 de Jun. de 2012
It's slow because you're using it in a loop. You don't need to call it in a loop. You can just call it on your labeled image once. But it gives you a binary image so you'd have to multiply that by your labeled image to get the endpoints associated with particular objects. Then you'd use that masked labeled image in the loop instead of calling bwmorph each time.
If you know for a fact that PixelList has the first element as one endpoint, and the last element as the last element, then you can use your method. However I doubt this is the case. What is you had a blob instead of a line? See what I mean? If not, run this simple example that illustrates why:
m = [0 0 2 0;0 2 0 0; 0 0 2 0]
measurements = regionprops(m, 'PixelList')
measurements.PixelList
ans =
2 2
3 1
3 3
The first pixel is the middle pixel (location 2,2) of the arc! Now you see why you need to do it like I said at the beginning. The first pixel at 3,1 is actually the second element of PixelList and the last pixel is that last element (so only that one is correct). You need to understand that connected components works by finding the upper left most pixel and then proceeding down rows first, then across columns after there are no more pixels in the current column. I know that's not particularly easy to find or well explained anywhere in the documentation that I know of, but if there is, Sean, Jeff, or Steve will direct you to it.
Más respuestas (1)
Thomas
el 22 de Jun. de 2012
You could lockup the Medical Image processing webinar which deals with toruosity.. You could also try bwdistgeodesic command..
doc bwdist
doc bwdistgeodesic
3 comentarios
Ver también
Categorías
Más información sobre Biomedical Imaging en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!