gpt4 book ai didi

imagemagick - 如何在 VIPS 中进行透视扭曲变换?

转载 作者:行者123 更新时间:2023-12-02 17:09:11 26 4
gpt4 key购买 nike

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

$ convert my_file.png -matte -virtual-pixel transparent +distort 透视 '0,0,0,60 1500,0,300,0 0,2100,0,2310 1500,2100,300,2100' -裁剪 300x2310+0+0

最佳答案

透视扭曲没有内置的东西,但你可以使用 mapim 制作一个:

http://jcupitt.github.io/libvips/API/current/libvips-resample.html#vips-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[3] + 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]

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

编辑:修复错字

关于imagemagick - 如何在 VIPS 中进行透视扭曲变换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50202733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com