- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我使用 MATLAB 的 imrotate
函数时,输出图像缺少部分,并用零填充。
我可以以某种方式使角上的三角形(即缺失的部分)充满图像的相对边缘吗?所以这就像我将图像与周围的 8 个相邻图像平铺,然后旋转并裁剪更大的图像?
感谢您的帮助,
最佳答案
我认为最好的(也是最有效的内存效率)方法是使用 interp2
在新的像素中心对原始图像进行采样(原始像素中心“旋转”所需角度的相反)。然后使用mod
在这些样本点上,以确保它们落在原始图像的尺寸内。 mod
的额外好处是,超出范围的新 x,y 坐标只需“环绕”到图像的另一侧。
% Load some sample image
load mri
im = double(D(:,:,12));
[rows, cols] = size(im);
% The original pixel centers
[xx,yy] = meshgrid(1:cols, 1:rows);
% Setup the rotation matrix
theta = pi/4;
R = [cos(-theta), -sin(-theta);
sin(-theta), cos(-theta)];
% Center of Rotation (center of the image)
center = [cols/2, rows/2];
% Determine the new pixel centers (rotated)
xy = bsxfun(@minus, [xx(:), yy(:)], center) * R;
xy = bsxfun(@plus, xy, center);
% Mod these using the dimensions of the image to "wrap" around
x = mod(xy(:,1) - 1, cols - 1) + 1;
y = mod(xy(:,2) - 1, rows - 1) + 1;
% Sample the original image at the new pixel centers
im2 = interp2(xx, yy, im, x, y);
im2 = reshape(im2, [rows, cols])
旋转 = 45 度
这适用于任意纵横比(下面的图像演示了 @BlackAdder 提出的问题,其中由于图像又高又窄,repmat [3,3] 不起作用)。
旋转 = 90 度
这还有一个额外的好处,即它不依赖于图像处理工具箱。
关于image - 使用 MATLAB imrotate 平铺图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35126181/
当我使用 MATLAB 的 imrotate 函数时,输出图像缺少部分,并用零填充。 我可以以某种方式使角上的三角形(即缺失的部分)充满图像的相对边缘吗?所以这就像我将图像与周围的 8 个相邻图像平铺
我试图在不使用 imrotate 函数的情况下使用 Matlab 旋转图像。我实际上是通过使用变换矩阵来实现的。但是它还不够好。问题是,旋转后的图像在“滑动”。让我用图片告诉你。 这是我要旋转的图像:
如何使用 OpenCV 2.4.3 实现 imrotate(Mat src,Mat dst,double angle)?有一个函数 warpAffine() 但它做的更多并且令人困惑。它会裁剪超出范围
我是一名优秀的程序员,十分优秀!