formula for distort function #540
-
Hi, In the test I render ideal images and apply the distortion on them, and I need to know how each ideal pixel is mapped to distorted pixel. so if you can help with that and give me the actual implementation of the function: or just the math formula that using the arguments list, any of the two will be perfect. Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The beauty of open source is that there's nothing stopping you from reading the source code. For distort formulas, check out distort.c in ImageMagick. The authors left plenty of math formulas as comments to help guide future readers. Here's an example of a comment for /*
Perspective Distortion (a ratio of affine distortions)
p(x,y) c0*x + c1*y + c2
u = ------ = ------------------
r(x,y) c6*x + c7*y + 1
q(x,y) c3*x + c4*y + c5
v = ------ = ------------------
r(x,y) c6*x + c7*y + 1
c8 = Sign of 'r', or the denominator affine, for the actual image.
This determines what part of the distorted image is 'ground'
side of the horizon, the other part is 'sky' or invalid.
Valid values are +1.0 or -1.0 only.
Input Arguments are sets of control points...
For Distort Images u,v, x,y ...
For Sparse Gradients x,y, r,g,b ...
Perspective Distortion Notes...
+ Can be thought of as ratio of 3 affine transformations
+ Not separatable: r() or c6 and c7 are used by both equations
+ All 8 coefficients must be determined simultaniously
+ Will only work with a 2 number_valuesal Image Distortion
+ Can not be used for generating a sparse gradient (interpolation)
+ It is not linear, but is simple to generate an inverse
+ All lines within an image remain lines.
+ but distances between points may vary.
*/ Most of the work in C is straight forward, but with a few look-up tables to manage coefficients & other repetitive routines. |
Beta Was this translation helpful? Give feedback.
The beauty of open source is that there's nothing stopping you from reading the source code. For distort formulas, check out distort.c in ImageMagick. The authors left plenty of math formulas as comments to help guide future readers.
Here's an example of a comment for
PerspectiveDistortion