首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在VIPS中执行透视失真转换?

如何在VIPS中执行透视失真转换?
EN

Stack Overflow用户
提问于 2018-05-07 01:42:09
回答 1查看 383关注 0票数 2

是否可以使用VIPS执行以下ImageMagick perspective distort命令?如果是,命令是什么(使用ruby-vips)?

$ convert my_file.png -matte -virtual-pixel transparent +distort Perspective '0,0,0,60 1500,0,300,0 0,2100,0,2310 1500,2100,300,2100' -crop 300x2310+0+0

EN

回答 1

Stack Overflow用户

发布于 2018-05-08 01:41:08

没有内置的透视扭曲功能,但您可以使用mapim创建一个

http://jcupitt.github.io/libvips/API/current/libvips-resample.html#vips-mapim

代码语言:javascript
复制
#!/usr/bin/ruby

require 'vips'

image = Vips::Image.new_from_file ARGV[0]

# perspective distortion: each pixel (x', y') in the output image is
# interpolated from pixel (x, y) in the input using:
#
#   x' = (A x + B y + C) / (G x + H y + 1)
#   y' = (D x + E y + F) / (G x + H y + 1)
#
# where the constants A .. H are from the transform matrix T
#
# T = [A, B, .. H]

T = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0003, 0.0001]

# make an index image where pixels have the value of their (x, y) coordinates
i = Vips::Image.xyz image.width, image.height

x = (i[0] * T[0] + i[1] * T[1] + T[2]) / (i[0] * T[6] + i[1] * T[7] + 1)
y = (i[0] * T[2] + i[1] * T[4] + T[5]) / (i[0] * T[6] + i[1] * T[7] + 1)

# join up x and y as a map image
m = x.bandjoin y

# and use it to transform our original image
image = image.mapim m 

image.write_to_file ARGV[1]

当然,您还需要一些东西来计算一组连接点的转换。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50202733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档