How to traverse along image?

조회 수: 4 (최근 30일)
asdf
asdf 2018년 5월 21일
편집: asdf 2018년 5월 24일
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
Walter Roberson
Walter Roberson 2018년 5월 21일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2018년 5월 21일
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 2018년 5월 21일
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
Image Analyst
Image Analyst 2018년 5월 21일
편집: Image Analyst 2018년 5월 22일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by