如何将一张普通图片做出鱼眼特效!!!求算法,求源码!!!

ezhourenwd 2011-03-28 03:54:42
现在有一张普通的图片。我要写一段代码实现鱼眼的效果。不知道算法。求高手指导。如果有源码更好。


在线等!!!
...全文
506 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
银杏草 2012-08-24
  • 打赏
  • 举报
回复
C#原链接:http://www.codeproject.com/Articles/19712/Mapping-Images-on-Spherical-Surfaces-Using-C
//java代码:不知道为什么改成java的精度降低了,水平有限啊
double phi0 = 0.0;
double phi1 = Math.PI;
double theta0 = 0.0;
double theta1 = 2.0*Math.PI;
double x0,y0,z0;

//计算经纬度
public static double MapCoordinate(double i1, double i2, double w1,double w2, double p){
return ((p - i1) / (i2 - i1)) * (w2 - w1) + w1;
}

public void draw(int radius,Graphics g){ //半径和Graphics上下文
for (int i = 0; i < w; i++) //图像宽度
{
for (int j = 0; j < h; j++) //图像高度
{
// map the angles from image coordinates
double theta = MapCoordinate(0.0, w - 1,theta1, theta0, i);//经度
double phi = MapCoordinate( 0.0, h - 1,phi0, phi1, j);//纬度

// find the cartesian coordinates //经纬度映射到大圆平面的座标
x0 = radius * Math.sin(phi) * Math.cos(theta);
y0 = radius * Math.sin(phi) * Math.sin(theta);
z0 = radius * Math.cos(phi);

// apply rotation around X and Y axis to reposition the sphere
RotX(1.5, y0, z0);
RotY(-2.5, x0, z0);
// plot only positive points
if (z0 > 0){
g.setColor(new Color(pix[i+j*w]));//pix[w*h]为图像的像素数组
int ix = (int)x0 + 150; //java可以用BufferedImage 对象的
int iy = (int)y0 + 150; //getRGB(0, 0,w , h, pix, 0, w)方法获得
g.fillOval(ix,iy,5,5);//没有找到setPoint函数用画圆代替了.
}
}
}
}

public void RotX(double angle, double y, double z)//旋转
{
double y1 = y * Math.cos(angle) - z * Math.sin(angle);
double z1 = y * Math.sin(angle) + z * Math.cos(angle);
y0 = y1;
z0 = z1;
}
public void RotY(double angle, double x, double z)
{
double x1 = x * Math.cos(angle) - z * Math.sin(angle);
double z1 = x * Math.sin(angle) + z * Math.cos(angle);
x0 = x1;
z0 = z1;
}
public void RotZ(double angle, double x, double y)
{
double x1 = x * Math.cos(angle) - y * Math.sin(angle);
double y1 = x * Math.sin(angle) + y * Math.cos(angle);
x0 = x1;
y0 = y1;
}

效果图
http://tieba.baidu.com/f?kz=1040536645
bluewanderer 2011-03-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ezhourenwd 的回复:]
不是这么处理的。应该是原图片对应一个圆,离圆心越近的点偏移越大,如果要达到理想的效果要具体的算法。。哪位大大指点下撒。。。。
[/Quote]

劝你先复习下基本的函数知识吧...
luciferisnotsatan 2011-03-28
  • 打赏
  • 举报
回复
这源码是求不到的。
lz你到 数据结构与算法 那个板块求个算法名吧。
ezhourenwd 2011-03-28
  • 打赏
  • 举报
回复
不是这么处理的。应该是原图片对应一个圆,离圆心越近的点偏移越大,如果要达到理想的效果要具体的算法。。哪位大大指点下撒。。。。
bluewanderer 2011-03-28
  • 打赏
  • 举报
回复
1. 最终的结果的每一点都对应了原始图片上的一点,而表示这种对应只需要一个函数。
2. 这个函数可能把整数位之的点比如(1, 2)映射到非整数点上去比如(1.1, 2.3),处理这个问题的方法最简单的就是线性插入。
ezhourenwd 2011-03-28
  • 打赏
  • 举报
回复
高手在哪里。。。求解答。。。求学习~~~

69,375

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧