Filter löschen
Filter löschen

How to extract values from a matrix along a certain line (not vertical or horizontal).

5 Ansichten (letzte 30 Tage)
Assume I have the following matrix:
A=[11 13 43 53 66 45 44 83 91;
23 43 54 65 76 78 76 98 33;
23 54 65 76 43 16 38 27 65]
I want to extract values from this matrix, along 45 degrees, to form a new matrix
B=[11 13 43 53 66 45 44;
43 54 55 76 78 76 98;
65 76 43 16 38 27 65]
How I can do it in MATLAB? Thanks.

Antworten (2)

Image Analyst
Image Analyst am 25 Okt. 2015
If you have the Image Processing Toolbox, simply use improfile().
  2 Kommentare
Image Analyst
Image Analyst am 25 Okt. 2015
Or, call imrotate() to align the image with rows or columns, and extract a row or column. Should be pretty close to the same thing.
Image Analyst
Image Analyst am 25 Okt. 2015
improfile() will extract along a line at an arbitrary angle - it doesn't have to be exactly 45 degrees. You just specify the two endpoints of the line and how many points along that line you want to interpolate.

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 25 Okt. 2015
A = [11 13 43 53 66 45 44 83 91; ...
23 43 54 65 76 78 76 98 33; ...
23 54 65 76 43 16 38 27 65];
[m, n] = size(A);
index = true(m, n);
index = tril(triu(index), n - m);
B = reshape(A(index), m, [])
  2 Kommentare
Image Analyst
Image Analyst am 25 Okt. 2015
Doesn't give what he wanted, but I'm not sure how he got that anyway. For example it sort of appears that it's a rotation about the middle element, but not quite. Because using
B=imrotate(A, -45, 'crop')
will give
B =
0 54 65 65 53 66 0 0 0
0 0 76 76 76 45 45 0 0
0 0 0 43 16 78 44 83 0
while Jan's code gives:
B =
11 43 53 66 45 44 98
13 54 65 76 78 76 27
43 65 76 43 16 38 65
Neither of which is
B=[11 13 43 53 66 45 44;
43 54 55 76 78 76 98;
65 76 43 16 38 27 65]
which the user asked for. So I need Peng to explain how B was arrived at. Also, Jan's code is for 45 degrees, which is the example angle Peng wanted, but in the subject line Peng asked for an "Arbitrary angle:. So which is it?? 45 or arbitrary? And if it's just a rotation, then why is B two columns (but no rows) shorter? If anything a rotated matrix would be larger, and you can get that with the 'loose' option to imrotate() where it will expand the canvass to hold the entire rotated matrix.
Peng
Peng am 25 Okt. 2015
Sorry, I did not state it clearly. I would like to extract value from a matrix along a line, e.g. for columns, the line is vertical, but now I want to extract the values along a line with 45 degrees. I am not sure if it is about the rotation of a matrix.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by