公式
设初始坐标为
(
x
0
,
y
0
)
\left (x_{0},y_{0}\right)
(x0?,y0?)的点经过平移
(
Δ
x
,
Δ
y
)
\left (\Delta x,\Delta y\right)
(Δx,Δy)后坐标变为
(
x
1
,
y
1
)
\left (x_{1},y_{1}\right)
(x1?,y1?),其关系如下 ?????????????????????????????????????????????????
{
x
1
=
x
0
+
Δ
x
y
1
=
y
0
+
Δ
y
\left\{\begin{matrix}x_{1}=x_{0}+\Delta x\\ y_{1}=y_{0}+\Delta y\end{matrix}\right.
{x1?=x0?+Δxy1?=y0?+Δy? 平移变换的矩阵表示为 ????????????????????????????????????????????
[
x
1
y
1
1
]
=
[
1
0
Δ
x
0
1
Δ
y
0
0
1
]
[
x
0
y
0
1
]
=
[
x
0
+
Δ
x
y
0
+
Δ
y
1
]
\begin{bmatrix}x_{1}\\ y_{1}\\ 1\end{bmatrix}=\begin{bmatrix}1 & 0 &\Delta x \\ 0& 1 & \Delta y\\ 0& 0 & 1\end{bmatrix}\begin{bmatrix}x_{0}\\ y_{0}\\ 1\end{bmatrix}=\begin{bmatrix}x_{0}+\Delta x\\ y_{0}+\Delta y\\ 1\end{bmatrix}
???x1?y1?1????=???100?010?ΔxΔy1???????x0?y0?1????=???x0?+Δxy0?+Δy1????
源代码
clc
image = imread('D:\2.png');
image_matrix=image(:,:,1);
image_matrix=double(image_matrix);
[height,width,channels]=size(image);
G=zeros(height,width);
%%水平,竖直方向上的平移值
height_move = 20;
width_move= 40;
for i=1:height
for j=1:width
%平移后的新坐标
i1=i+height_move;
j1=j+width_move;
if(i1>=0 && i1<=height && j1>=0 && j1<=width)
G(i1,j1)=image_matrix(i,j);
else
G(i,j)=255;
end
end
end
image_out = uint8(G);
%显示
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
imshow(image_out);
效果图
|