Avoiding jagged edges with mapim
?
#323
-
Hi, I'm following this example to achieve perspective distortion with It's working great, except for one small issue with jagged edges which I haven't yet figured out how to avoid. Perhaps someone knows how to avoid the jagged edges? require "vips"
image = Vips::Image.new_from_file "input.png"
t = [1.73945282, -0.41595611, -116.35426798, 5.97741712e-01, 2.47280054e+00, -6.75608244e+02, -1.59808198e-06, 4.97586518e-06]
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)
m = x.bandjoin y
distorted_image = image.mapim m
distorted_image.write_to_file "output.png" |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Seems similar to libvips/php-vips#58 ("affine should have a background parameter, and not have jaggy edges") |
Beta Was this translation helpful? Give feedback.
-
Hi @GavinJoyce, You could put a one-pixel black border around the source. Eg.: #!/usr/bin/ruby
require "vips"
image = Vips::Image.new_from_file ARGV[0]
image = image.embed 1, 1, image.width + 2, image.height + 2
t = [1.73945282, -0.41595611, -116.35426798, 5.97741712e-01, 2.47280054e+00, -6.75608244e+02, -1.59808198e-06, 4.97586518e-06]
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)
m = x.bandjoin y
distorted_image = image.mapim m
distorted_image.write_to_file ARGV[1] To make: |
Beta Was this translation helpful? Give feedback.
-
... but you're right, improving |
Beta Was this translation helpful? Give feedback.
-
Thanks for the workaround @jcupitt, that works a treat |
Beta Was this translation helpful? Give feedback.
-
... this is fixed in master and will be in 8.13. |
Beta Was this translation helpful? Give feedback.
Hi @GavinJoyce,
You could put a one-pixel black border around the source. Eg.:
To make: