几何变换:在Python中重现Gimp扭曲工具

问题描述 投票:0回答:1

我想用Python重现Gimp扭曲工具,特别是“Grow”转换。

例如,输入图像:

我想获得:

这是我要编写的代码的模板:

import cv2
import numpy as np
import math
from operator import itemgetter

def growth_area(in_img, parameters):
    #in_img comes from cv2.imread('./test_image.png', cv2.IMREAD_GRAYSCALE)
    size, strength, hardness, position = itemgetter('size', 'strength', 'hardness', 'position')(parameters) 
    img_out = np.zeros(in_img.shape, dtype=in_img.dtype)
    rows, cols = in_img.shape
    # Here I want to implement the code 
    # to get the transformation shown in 
    # the pictures, and show the result in img_out
    cv2.imshow('warp', img_out)
    cv2.waitKey()

我想用4个参数

growth_area()
来控制
'size', 'strength', 'hardness', 'position'
的执行,其中前3个参数的行为与Gimp中的3个参数相同,最后一个
'position'
代表变换的中心。我怎样才能实现这个?

python opencv image-processing gimp
1个回答
0
投票

我正在尝试像你一样做。我已经在 gimp 和 gegl 的代码中调试了这个功能。我注意到它们生成位移图来实现扭曲变换功能。有关生成的位移的文件位于名为“warp”的 Gegl 项目中.cc'。但是我遇到了与您相同的问题。我无法弄清楚解释此函数的算法。你在这方面有进展吗?

© www.soinside.com 2019 - 2024. All rights reserved.