use*_*729 9 matlab geometry image-processing
如何实现该图像中所示的鱼眼镜头效果:
可以尝试使用Google的徽标:
顺便说一下,它的用语是什么?
gno*_*ice 13
我相信这通常被称为"鱼眼镜头"效果或"桶形变换".以下是我发现的两个演示链接:
使用该功能执行桶形变换的图像处理演示tformarray
.
在这个例子中,我radial.m
从上面的第一个链接开始使用函数,并修改了它与输入和输出空间之间的点相关的方式,以创建一个漂亮的圆形图像.fisheye_inverse
下面给出了新函数,它应该放在MATLAB路径的一个文件夹中,以便稍后在本例中使用它:
function U = fisheye_inverse(X, T)
imageSize = T.tdata(1:2);
exponent = T.tdata(3);
origin = (imageSize+1)./2;
scale = imageSize./2;
x = (X(:, 1)-origin(1))/scale(1);
y = (X(:, 2)-origin(2))/scale(2);
R = sqrt(x.^2+y.^2);
theta = atan2(y, x);
cornerScale = min(abs(1./sin(theta)), abs(1./cos(theta)));
cornerScale(R < 1) = 1;
R = cornerScale.*R.^exponent;
x = scale(1).*R.*cos(theta)+origin(1);
y = scale(2).*R.*sin(theta)+origin(2);
U = [x y];
end
Run Code Online (Sandbox Code Playgroud)
当应用于方形图像时,鱼眼失真看起来最佳,因此您需要通过裁剪或用某种颜色填充图像来使图像成为方形.由于图像的转变看起来不正确的索引图像,你也想任何索引图像转换为RGB图像使用ind2rgb
.灰度或二进制图像也可以正常工作.以下是针对您的示例Google徽标执行此操作的方法:
[X, map] = imread('logo1w.png'); % Read the indexed image
rgbImage = ind2rgb(X, map); % Convert to an RGB image
[r, c, d] = size(rgbImage); % Get the image dimensions
nPad = (c-r)/2; % The number of padding rows
rgbImage = cat(1, ones(nPad, c, 3), rgbImage, ones(nPad, c, 3)); % Pad with white
Run Code Online (Sandbox Code Playgroud)
现在我们可以创建变换maketform
并应用它imtransform
(或者imwarp
在新版本中推荐):
options = [c c 3]; % An array containing the columns, rows, and exponent
tf = maketform('custom', 2, 2, [], ... % Make the transformation structure
@fisheye_inverse, options);
newImage = imtransform(rgbImage, tf); % Transform the image
imshow(newImage); % Display the image
Run Code Online (Sandbox Code Playgroud)
这是您应该看到的图像:
您可以通过更改options
数组中的第三个值来调整失真度,这是图像点径向变形中使用的指数幂.