Imagemagick 如何在VIP中执行透视扭曲转换?

Imagemagick 如何在VIP中执行透视扭曲转换?,imagemagick,transformation,imagemagick-convert,vips,Imagemagick,Transformation,Imagemagick Convert,Vips,是否可以使用VIP执行以下ImageMagick命令?如果是这样,该命令是什么(使用ruby vips) $convert my_file.png-matte-virtual pixel transparent+扭曲透视图'0,0,0,60 1500,0300,0 02100,02310 150021003002100'-crop 300x2310+0+0透视图扭曲没有内置功能,但可以使用mapim制作一个: 当然,您还需要一些东西来从一组连接点计算变换 #!/usr/bin/ruby re

是否可以使用VIP执行以下ImageMagick命令?如果是这样,该命令是什么(使用
ruby vips


$convert my_file.png-matte-virtual pixel transparent+扭曲透视图'0,0,0,60 1500,0300,0 02100,02310 150021003002100'-crop 300x2310+0+0
透视图扭曲没有内置功能,但可以使用
mapim
制作一个:

当然,您还需要一些东西来从一组连接点计算变换

#!/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]