matlab练习程序(图像水平/竖直移动)
时间: 2023-08-04 18:27:41 浏览: 85
这是一个简单的 Matlab 程序,可以实现图像的水平或竖直移动。你可以按照自己的需要修改代码中的参数,比如移动距离、方向等。
```matlab
% 读入图像
img = imread('lena.png');
% 显示原图像
figure, imshow(img), title('Original Image');
% 图像水平移动
shift_distance = 50; % 移动距离
shifted_img = imtranslate(img, [shift_distance, 0], 'FillValues', 0);
% 显示移动后的图像
figure, imshow(shifted_img), title('Horizontally Shifted Image');
% 图像竖直移动
shift_distance = 50; % 移动距离
shifted_img = imtranslate(img, [0, shift_distance], 'FillValues', 0);
% 显示移动后的图像
figure, imshow(shifted_img), title('Vertically Shifted Image');
```
在这个程序中,我们使用了 `imread` 函数读入一张图像,然后使用 `imshow` 函数显示原图像。接着,我们分别使用 `imtranslate` 函数实现图像的水平或竖直移动,并使用 `imshow` 函数显示移动后的图像。注意,在移动图像时,我们会将移动后的空白部分设置为 0,这是通过 `FillValues` 参数实现的。
阅读全文
相关推荐










