How to create image matrix via
이전 댓글 표시
I have the following problem: I have a file.mat, containing a matrix 240X320. If I click on imagesc, I see an image referencing the matrix ... Now, I want to select a portion of the image by clicking on "insert-> rectangle" and from there derive the submatrix. If I click with right mouse button I can show M-code, which gives me only the coordinates of the rectangle, but how can I obtain the submatrix?
채택된 답변
추가 답변 (7개)
Andrei Bobrov
2011년 8월 18일
M = randi([-123 421],10) % your matrix
xy = [2,7;4,8] % coordinates of your rectangle in view [x1,x2;y1,y2]
variant
c = arrayfun(@(i1)xy(i1,1):xy(i1,2),1:2,'un',0);
SM = M(c{:}) % your submatrix
or
SM = M(xy(1,1):xy(1,2),xy(2,1):xy(2,2)) % your submatrix
Vincenzo
2011년 8월 18일
댓글 수: 1
Image Analyst
2011년 8월 20일
Your row1, etc. are fractional numbers. You need to use round(), floor(), ceil(), or int32() to get them into integers.
Walter Roberson
2011년 8월 18일
0 개 추천
This sounds oddly like yesterday's question http://www.mathworks.com/matlabcentral/answers/13866-move-rectangle-over-te-image
Vincenzo
2011년 9월 7일
댓글 수: 2
Walter Roberson
2011년 9월 7일
x1=0.3867;
row1=int32(x1*320);
That is, do not convert the multiplication factor to integer: convert the result of the multiplication to integer.
Vincenzo
2011년 9월 8일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!