Borrar filtros
Borrar filtros

How to traverse along image?

2 visualizaciones (últimos 30 días)
asdf
asdf el 21 de Mayo de 2018
Editada: asdf el 24 de Mayo de 2018
I am using this code to highlight the boundaries of an image
I=imread(image);
boundaries=bwboundaries(I);
numboundaries=size(boundaries,1);
for k=1:numboundaries
thisboundary=boundaries{k};
L=size(thisboundary(:,2));
for j=1:100:L(1)
plot(thisboundary(j,2), thisboundary(j,1), '*g')
end
end
I have an example image:
This is an example of how the order in which the `for j=1:100:L(1)` traverses:
What I would like instead is to traverse along the boundary in the order specified in the image below. I would like to be able to draw straight lines and get their coordinates, like the green straight lines I've drawn
Or is it possible to convert the white thick curve using imerode and/or imdilate so that the white curve consists of only one white pixels. For example, for the 3rd image, is it possible to thin the white thick part so that the green straight lines only go through one white pixel?
Is this possible in Matlab? How can I do this?
  1 comentario
Walter Roberson
Walter Roberson el 21 de Mayo de 2018
imread() never returns a cell array, so I is not going to be a cell array. You assign I to boundaries, so boundaries is not going to be a cell array. But you access boundaries{k} as if it were a cell array.

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 21 de Mayo de 2018
For you I would suggest https://www.mathworks.com/help/images/ref/bwtraceboundary.html which allows you to specify an initial position and initial search direction.

Image Analyst
Image Analyst el 21 de Mayo de 2018
I think your whole approach is wrong. I think what you really want is the mean width or the distribution of widths. To do that you'd call bwdist() to get the Euclidean distance transform, then call bwmorph on the binary image to get the skeleton, then use the skeleton as a mask/index on the EDT image to extract the radii. Then get the mean of those or histogram them. The steps are (untested):
edtImage = bwdist(binaryImage);
skelImage = bwmorph(binaryImage, 'skel', inf);
radiiValues = edtImage(skelImage);
diameterValues = 2 * radiiValues;
histogram(diameterValues );
meanDiameter= mean(diameterValues);
  1 comentario
Image Analyst
Image Analyst el 21 de Mayo de 2018
Editada: Image Analyst el 22 de Mayo de 2018
You can get the skeleton like I said. Then get the endpoints and use bwtraceboundary() to move along the skeleton. You can move along the curve and fit the points in a window to a quadratic. Then get the slope and find the endpoints of a line perpendicular to the curve at that point. You can find the width of the perpendicular line by taking the max of the EDT image - that will tell you how long to make the cross sectional line. Then with the endpoints of the cross section you can call imline() or improfile() and with that you can find the width. Not too hard. Do you want to try it yourself?
I'm attaching code to give you a start. See if you can finish it.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by