Skip to content

Avoiding jagged edges with mapim? #323

Answered by jcupitt
GavinJoyce asked this question in Q&A
Discussion options

You must be logged in to vote

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:

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by GavinJoyce
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jcupitt
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants