Image rotation and NaN elements

조회 수: 3 (최근 30일)
Sordin
Sordin 2017년 4월 6일
편집: KSSV 2017년 4월 6일
The following code rotates an image by a given angle θ. I do not understand the function and significance of the last line:
n = size(Image,1);
x = linspace(-1,1,n);
[X1,Y1] = meshgrid(x,x);
% Coordinate rotation
X = cos(theta)*X1 + -sin(theta)*Y1;
Y = sin(theta)*X1 + cos(theta)*Y1;
% Interpolation
RotatedImage = interp2(X1,Y1,Image,X,Y);
RotatedImage(isnan(RotatedImage)) = 0;
If I understand correctly, it eliminates the elements in the final image that are NaN. But why would the rotation or interpolation introduce elements which are not-a-number?
When I omit this line, the resulting image looks nothing like the original image. Without this line, is there any alternative way of avoiding NaN elements?
Any explanation would be appreciated.

채택된 답변

KSSV
KSSV 2017년 4월 6일
편집: KSSV 2017년 4월 6일
RotatedImage = interp2(X1,Y1,Image,X,Y);
It introduces NaN's at the points, which are not in range. As it is not using extrapolation. So those NaN's are replaced with zeros. Read about interp2, how it is associated with extrapolation.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by