Indexing a matrix along a specific direction
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sami hawasli
el 25 de Sept. de 2018
Editada: sami hawasli
el 26 de Sept. de 2018
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 comentarios
Matt J
el 25 de Sept. de 2018
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?
Respuesta aceptada
Matt J
el 25 de Sept. de 2018
Editada: Matt J
el 25 de Sept. de 2018
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 comentario
Más respuestas (1)
jonas
el 25 de Sept. de 2018
Editada: jonas
el 25 de Sept. de 2018
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.
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots 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!