how to change the index image created by vips_xyz() #3636
crazyjudas
started this conversation in
Help wanted
Replies: 2 comments 2 replies
-
Hi @crazyjudas, You can use any of the libvips operations to manipulate the index image. You can think of the For example: #!/usr/bin/env python
import sys
import pyvips
image = pyvips.Image.new_from_file(sys.argv[1])
t = [
1.73945282, -0.41595611, -116.35426798,
5.97741712e-01, 2.47280054e+00, -6.75608244e+02,
-1.59808198e-06, 4.97586518e-06
]
i = pyvips.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)
m = x.bandjoin(y)
distorted_image = image.mapim(m)
distorted_image.write_to_file(sys.argv[2]) Is an affine transform, or: #!/usr/bin/python3
import math
import sys
import pyvips
original = pyvips.Image.new_from_file(sys.argv[1])
# stretch the image out so we have lots of spare edge pixels
image = original.gravity("centre",
original.width * 3,
original.height * 3,
extend="copy")
# this makes an image where pixel (0, 0) (at the top-left) has value [0, 0],
# and pixel (image.width, image.height) at the bottom-right has value
# [image.width, image.height]
index = pyvips.Image.xyz(image.width, image.height)
# move the origin to the centre, negative values up and left,
# positive down and right
centre = index - [image.width / 2, image.height / 2]
# to polar space, so each pixel is now distance and angle in degrees from the
# centre
polar = centre.polar()
# swap distance around so we have 1 in the centre and 0 at the edges of the
# original image size ... square, so we have a gentler twist at the edge
size = min(original.width, original.height) / 2
d = (1 - polar[0] / size) ** 2
# add to a so we swirl by 180 degrees in the centre and 0 at the edges
a = polar[1] + d * 180
# and back to rectangular coordinates again to make a set of vectors we can
# apply to the original image
distort = polar[0].bandjoin(a).rect() + [image.width / 2, image.height / 2]
# distort the image
interp = pyvips.Interpolate.new("bicubic")
distorted = image.mapim(distort, interpolate=interp)
# crop out the original again
image = distorted.crop(original.width,
original.height,
original.width,
original.height)
image.write_to_file(sys.argv[2]) Makes a bizarre swirling effect, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having trouble understanding how to change the index image.
the src image is
https://drive.google.com/file/d/1Um2ogIE1B8vlxiUZGognP69kF13Iis4X/view?usp=drive_link
the destination transform image is
https://drive.google.com/file/d/12DL04VVMm3qtPrfsKmqhmudXualgaOZm/view?usp=drive_link
the src coordinate and des coordinate is as follows
https://drive.google.com/file/d/14MK8GPsQFBRu9lxsi5DwfNPb8tY9swqc/view?usp=drive_link
How can I do this transform use mapim()?
I don't know how to build the index image.
the index image built by others is as follows:
https://drive.google.com/file/d/15j3bHC6qnAspWXnOFsG6AZiWrhgYz04Z/view?usp=drive_link
Beta Was this translation helpful? Give feedback.
All reactions