使用三角函数和图像填充旋转图像 [英] Rotating image with trigonometric functions and image padding

查看:177
本文介绍了使用三角函数和图像填充旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旋转具有三角函数的图像时,我们使用的是图像填充.

While rotating image with trigonometric function we are using image padding.

如果我们旋转而没有填充,我们将得到以下图片:

If we rotate without padding we have this picture:

如果我们填充图片, 例如,使用以下代码:

If we pad the picture, For instance with these codes:

`Padding_Bottom_And_Top = zeros(round(Image_Height/2),Image_Width,3);
Side_Padding = zeros(Image_Height+2*size(Padding_Bottom_And_Top,1),Image_Width/2,3);
Side_Padding =zeros(Image_Height+2*size(Padding_Bottom_And_Top,1),Image_Width/2,3);
Padded_Image = [Padding_Bottom_And_Top; Original_Image];
Padded_Image = [Padded_Image; Padding_Bottom_And_Top];
Padded_Image = [Side_Padding Padded_Image];
Padded_Image = [Padded_Image Side_Padding];`

我们有这张照片

首先,我想学习这段代码的工作方式? 其次,我们使用图像填充实现了什么?

First, i want to learn how this code piece is working? Secondly, what we achieve with using image padding?

推荐答案

图像填充

下面的这个操场脚本可能有助于将零填充置于透视图中.这里使用的填充是顶部和底部填充的图像高度的一半,而侧面填充的图像宽度的一半.本质上,填充是将零(黑色像素)的数组连接到图像的侧面.在这种情况下,它可以旋转图像而不会剪切图像.填充后的图像将具有一定的边距,以使转角在旋转时不会溢出图像的边界.使用padarray()函数可以获得相同的结果,这也是一种合适的方法.有关旋转的详细信息,请参见:使用三角函数旋转图像

使用padarray()函数的替代方法:

Image Padding

This playground script below might help to put zero-padding into perspective. Here the padding used is half the image height for the top and bottom padding and half the image width for the side padding. Essentially padding is concatenating arrays of zeros (black pixels) to the sides of the image. In this case, it allows the image to be rotated without clipping the image. The padded image will have some margin so that the corners do not overflow the bounds of the image upon rotation. Using the padarray() function can achieve the same results which is also a suitable method. For details regarding rotating specifically see: Rotating image with trigonometric functions

clf;
Original_Image = imread("peppers.png");
[Image_Height,Image_Width,Number_Of_Colour_Channels] = size(Original_Image);
Padded_Image = padarray(Original_Image,[Image_Height/2 Image_Width/2],0,'both');
imshow(Padded_Image);

clf;
Original_Image = imread("peppers.png");
[Image_Height,Image_Width,Number_Of_Colour_Channels] = size(Original_Image);

Padding_Bottom_And_Top = zeros(round(Image_Height/2),Image_Width,Number_Of_Colour_Channels);
Side_Padding = zeros(Image_Height+2*size(Padding_Bottom_And_Top,1),Image_Width/2,Number_Of_Colour_Channels);

subplot(2,4,1); imshow(Padding_Bottom_And_Top);
title("Top and Bottom Padding");

subplot(2,4,2); imshow(Side_Padding);
title("Side Padding"); 

Padded_Image = [Padding_Bottom_And_Top; Original_Image];
subplot(2,4,5); imshow(Padded_Image);
title("Top Padding");

Padded_Image = [Padded_Image; Padding_Bottom_And_Top];
subplot(2,4,6); imshow(Padded_Image);
title("Top and Bottom Padding");


Padded_Image = [Side_Padding Padded_Image];
subplot(2,4,7); imshow(Padded_Image);
title("Top, Bottom and Left Padding");


Padded_Image = [Padded_Image Side_Padding];
subplot(2,4,8);imshow(Padded_Image);
title("Top, Bottom, Left and Right Padding");

使用MATLAB R2019b进行运行

这篇关于使用三角函数和图像填充旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆