(image: pyvips.Image, couples: List[Couple])
return image.mapim(index, interpolate=pyvips.Interpolate.new('bicubic'))
Shepard's distortion.

    Distort an image with a set of control points.
Shepard's distortion.
Shepard s distortion .
def shepards(image: pyvips.Image, couples: List[Couple]) -> pyvips.Image:
    """Shepard's distortion.

    Distort an image with a set of control points.
    """

    index = pyvips.Image.xyz(image.width, image.height)
    deltas = []
    weights = []
    for p1, p2 in couples:
        diff = index - list(p2)

        distance = (diff[0]**2 + diff[1]**2)
        distance = distance.ifthenelse(distance, 0.1)

        weight = 1.0 / distance

        delta = [(p1[0] - p2[0]), (p1[1] - p2[1])] * weight

        weights.append(weight)
        deltas.append(delta)

    # add, normalize
    index += pyvips.Image.sum(deltas) / pyvips.Image.sum(weights)

    return image.mapim(index, interpolate=pyvips.Interpolate.new('bicubic'))
def shepards ( image : pyvips . Image , couples : List [ Couple ] ) -> pyvips . Image : index = pyvips . Image . xyz ( image . width , image . height ) deltas = [ ] weights = [ ] for p1 , p2 in couples : diff = index - list ( p2 ) distance = ( diff [ 0 ] ** 2 + diff [ 1 ] ** 2 ) distance = distance . ifthenelse ( distance , 0.1 ) weight = 1.0 / distance delta = [ ( p1 [ 0 ] - p2 [ 0 ] ) , ( p1 [ 1 ] - p2 [ 1 ] ) ] * weight weights . append ( weight ) deltas . append ( delta ) # add, normalize index += pyvips . Image . sum ( deltas ) / pyvips . Image . sum ( weights ) return image . mapim ( index , interpolate = pyvips . Interpolate . new ( 'bicubic' ) )