Indexing a matrix along a specific direction

10 次查看(过去 30 天)
Hello all,
I apologize ahead of time for writing such a long question, but a bit of context seems necessary. I was wondering what is the best way to index within a matrix along a particular direction or slope?
I am performing line edge detection using a matrix which contains topographical data. Each index in the matrix contains a value which corresponds to a particular height, the picture below shows the matrix converted to a RBG image along with two white lines which I have determined to be the edges.
(Blue is min, Red is max height)
The goal is to calculate the cross sectional area (in the Y direction) at various points along this line, however, undoubtedly the line data/picture is not 100% perpendicular with respect to the Y axis. If it was perpendicular, i could simply index straight down a single column and calculate my area. To try and correct for the offset angle of the line, I perform a linear fit to the detected bottom edge and use the perpendicular slope of the fitted line to determine what index along the top edge lies perpendicular to the bottom edge index.
Here lies my problem. The perpendicular line without fail will intercept the detected top edge in-between indices (see right side of above image). Its easy enough to solve for which X index within the top line is closest to perpendicular line, but (in the forum's collective mind) what would be the best algorithm for returning the indices/values from the bottom edge to the top, given a particular slope and closest X index in the top line. I want to create a plot like below that takes into account the offset angle of the line (the plot below is plotting straight down the first column of data).
I will share a google drive link to the data file, its too large to directly post here topographical data (Let me know if that link doesn't work) The first column is the Y-coordinates (in um), and every following column is the topographical data for each x-index ( the plot above is plot(data(:,1),data(:,2)) ). In the example above, if you use a bottom line edge's X-index of 500, the perpendicular line is closest to the top edge's x index of 503. The slope of the perpendicular line is 195.98 and in order to fully solve for the perpendicular line, the bottom edge is at (500,89.443).
Gosh I hope all that made sense, Thanks in advance, sorry again for the length of the question, Sami
  3 个评论
Matt J
Matt J 2018-9-25
To try and correct for the offset angle of the line, I perform a linear fit to the detected bottom edge and use the perpendicular slope of the fitted line
It seems rather arbitrary that the bottom line defines your x-axis. Why not the top line? Why not the bisector of the two lines?
sami hawasli
sami hawasli 2018-9-26
Choosing the bottom line was 100% arbitrary, but I had to start somewhere. Using the bisector is a great idea though.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2018-9-25
编辑:Matt J 2018-9-25
My approach would be to use imrotate to rotate the image so that the bottom line is horizontally aligned, using the slope/angle determined from your line fit. Then re-run the edge detection on the rotated image. Then, you can calculate separation distances between the top and bottom edges by direct indexing, like you were initially hoping to do.
  1 个评论
sami hawasli
sami hawasli 2018-9-26
编辑:sami hawasli 2018-9-26
Simple and elegant. Wish i saw / knew about imrotate a few weeks ago. Although it just occurred to me, I am using a matrix of data, not an image. Will imrotate work on a matrix of data rather than an image?
Imrotate totally worked on the matrix of data too! I really should have just tried it before asking.
Thanks!

请先登录,再进行评论。

更多回答(1 个)

jonas
jonas 2018-9-25
编辑:jonas 2018-9-25
I don't know about the forums collective mind, but I would approach this in a different way. When you have your line, just interpolate your surface along this line and calculate the height on the basis of the interpolated line. Let's say you have a line described by the coordiantes [x1;y1] and [x2;y2], simply use:
xp=linspace(x1,x2,1000);
yp=linspace(y1,y2,1000);
zp=interp2(x,y,z,xp,yp)
where x, y and z are the x-indices, y-values and height-data, respectively.
You may also want to consider removing some outliers, since you have quite a few. It could possibly prevent some trouble further down the road when calculating your area. For example:
z(isoutlier(z,'movmedian',200))=NaN;
z=fillmissing(z,'nearest');
And by the way, the question is very well written. Just because most people ask one-line questions does not mean that it is the way to go.

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by