How to do the grid sampling in the rotated square area of an image
조회 수: 2 (최근 30일)
이전 댓글 표시
As the following image shows, I want to do grid sampling in the rotated square area of an image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193720/image.png)
I need to get a matrix with a certain size and the values of this matrix are the grid pixel value of the image.
Is there an algorithm can do this? or is there a function in Matlab? I found some functions in the Matlab Answer, but all of them are not for the rotated square area as the second image shown.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193721/image.png)
댓글 수: 0
채택된 답변
KSSV
2018년 11월 1일
YOu can rotate the image in the way you want.
M = 50; N = 50 ;
x = linspace(0,1,M) ;
y = linspace(0,1,N) ;
[X,Y] = meshgrid(x,y) ;
th = 45 ;
R = [cos(th) -sin(th) ; sin(th) cos(th)] ;
coor = [(X(:)-mean(X(:))) (Y(:)-mean(Y(:)))]*R ;
Xi = mean(X(:))+reshape(coor(:,1),M,N) ;
Yi = mean(Y(:))+reshape(coor(:,2),M,N) ;
figure
hold on
plot(X,Y,'.r')
plot(Xi,Yi,'.b')
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!