鱼眼镜头图像畸变矫正(fish eye distortion)
2017-02-23 23:13
585 查看
from PIL import Image import math def fish_eye_dis(img): "fish eye distortion" width_in, height_in = img.size; im_out = Image.new("RGB",(width_in,height_in)); radius = max(width_in, height_in)/2; #assume the fov is 180 #R = f*theta lens = radius*2/math.pi; for i in range(width_in): for j in range(height_in): #offset to center x = i - width_in/2; y = j - height_in/2; r = math.sqrt(x*x + y*y); theta = math.atan(r/radius); if theta<0.00001: k = 1; else: k = lens*theta/r; src_x = x*k; src_y = y*k; src_x = src_x+width_in/2; src_y = src_y+height_in/2; pixel = im.getpixel((src_x,src_y)); im_out.putpixel((i,j),pixel); return im_out; if __name__=="__main__": input_name = "image0.jpg"; output_name = "image_dis.jpg"; im = Image.open(input_name); img_out = fish_eye_dis(im); img_out.save(output_name); print "fish eye distortion completely, save image to %s" % output_name
效果如下:
原图矫正后
原理参考:Fisheye lens Wikis
源代码地址(oschina.net):fish eye distortion.py
相关文章推荐
- fish's dotNET
- Google Eyeing Microsoft Territory?
- 爱护你自己就要像爱护你的EYE一样
- GlassFish FAQ
- GlassFish FAQ
- GlassFish FAQ
- 感谢zhuanshen712、qq22345111、lazyfish三位朋友
- E文积累_20080304_eat no fish and play the game
- Zend Framework中文化团队新站点开通--PHPEye.com
- 为什么ORM性能比iBATIS好?(作者:Javaeye Robbin)
- Integrating Seam with Maven, Netbeans and GlassFish
- GlassFish FAQ
- 酷图分享:The Eye of i
- 借鉴JGE的HGEDistortionMesh
- saveOrupdate方法如何使用 (转帖网址:http://www.javaeye.com/topic/2632)
- Sun GlassFish应用服务器
- [HOWTO]Best color to protect eye
- 总谐波失真(Total Harmonic Distortion,THD)
- 几个好玩的FISH好玩意
- 4大 Java OSGi 框架比较 (Knopflerfish, Apache Felix, Equinox, Spring DM)