如何在VIPS中执行透视变形? [英] How to perform perspective distort transformation in VIPS?

查看:75
本文介绍了如何在VIPS中执行透视变形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用VIPS执行以下ImageMagick 透视扭曲命令?如果是这样,命令是什么(使用 ruby​​-vips )?

Is it possible to do the following ImageMagick perspective distort command using VIPS? If so, what would the command be (using ruby-vips)?

$ convert my_file.png-遮罩-虚拟像素透明+扭曲透视图'0,0,0,60,1500,0,300,0 0,2100,0,2310 1500,2100,300,2100'-裁剪300x2310 + 0 + 0

推荐答案

透视图失真没有内置的东西,但是您可以使用 mapim 制作一个:

There isn't a built-in thing for perspective distort, but you can make one using 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[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]

当然,您还需要一些东西来根据一组联系点来计算转换.

You'd also need something to calculate the transform from a set of tie-points, of course.

这篇关于如何在VIPS中执行透视变形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆