Filter löschen
Filter löschen

Counting pixel at an angle without rotating image

1 Ansicht (letzte 30 Tage)
Hg
Hg am 21 Okt. 2015
Kommentiert: Image Analyst am 21 Okt. 2015
How to count the pixels along the line (red) that is perpendicular to the major axis (blue) of a region, without rotating the image?

Akzeptierte Antwort

Image Analyst
Image Analyst am 21 Okt. 2015
You know the centroid (xCentroid, yCentroid), and you know the slope (because you drew the line). The perpendicular slope is -1/mainSlope. The equation of a line is (y-y0) = slope * (x-x0). Or
perpSlope = -1 / mainSlope;
y = perpSlope * (x - x0) + y0;
Put in (x0,y0) of the point you want to take the cross section of - the point along the main slope. Then put in x = 1, for the left edge, and x = (number of columns in the image) for the right edge. That will get you two endpoints of the line. Then just call improfile() to get a line drawn across, and use find() to determine the x and y locations of where the line crosses the white region.
  2 Kommentare
Hg
Hg am 21 Okt. 2015
This works! Image Analyst, thanks for being a great help!
Image Analyst
Image Analyst am 21 Okt. 2015
You're welcome. I'm glad you were able to get it working with just the few steps that I outlined. And thanks for Accepting the answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by