聘我网

新概念招聘3.0

如何生成这种鱼眼效果?

vote up0vote downstar

alt text

 

2 个答复

vote up0vote downcheck
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

[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

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

效果:

alt text

链接
vote up0vote down
[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
options = [c/2 r/2 max(r,c)/2 0 0 0 1 0];  %# The options radial.m will use
tf = maketform('custom',2,2,[],@radial,options);  %# Transformation structure
newImage = imtransform(rgbImage,tf);  %# Transform the image
imshow(newImage);                     %# Display the image

参考这里:

http://www.mathworks.com/support/solutions/en/data/1-1LXFHZ/index.html?product=IP&solution=1-1LXFHZ

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.