필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
Peng
Peng 2015년 10월 25일
댓글: Image Analyst 2015년 10월 25일
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.

답변 (2개)

Image Analyst
Image Analyst 2015년 10월 25일
If you have the Image Processing Toolbox, simply use improfile().
  댓글 수: 2
Image Analyst
Image Analyst 2015년 10월 25일
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 2015년 10월 25일
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.

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


Jan
Jan 2015년 10월 25일
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
Image Analyst
Image Analyst 2015년 10월 25일
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 2015년 10월 25일
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.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by