Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
如何实现该图所示的鱼眼镜头效果:
![]() 可以使用Google的徽标进行尝试: ![]() 顺便说一句,这是什么意思? 回答: 我相信这通常被称为“鱼眼镜头”效果或“镜筒变换”。这是我找到的演示的两个链接:
在此示例中,我从上面的第一个链接开始使用函数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 = [xy]; end 鱼眼失真在应用于正方形图像时看起来最好,因此您将需要通过裁剪或用某种颜色填充使其成为正方形。由于索引的图像将无法正确显示图像 ,因此您还需要使用ind2rgb将任何索引的图像转换为RGB图像 。 灰度或二进制图像也可以正常工作。以下是您的示例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 = (cr)/2; % The number of padding rows rgbImage = cat(1, ones(nPad, c, 3), rgbImage, ones(nPad, c, 3)); % Pad with white 现在,我们可以创建一个变换maketform ,并应用它imtransform (或imwarp在新版本推荐): options = [cc 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 这是您应该看到的图像: ![]() 您可以通过更改options数组中的第三个值来调整变形程度,这是在图像点的径向变形中使用的指数幂。 更多&回答... |
![]() |
![]() |