Skip to content

Commit

Permalink
Add doctest example to FundamentalMatrixTransform class (#6863)
Browse files Browse the repository at this point in the history
* Add example to fundamental matrix class
* Fix precision for parameters
* Fix precision of estimate function
* Fix precision of inverse function
* Add description to examples

Co-authored-by: Lars Grüter <lagru+github@mailbox.org>
  • Loading branch information
ana42742 and lagru committed Dec 15, 2023
1 parent e964c61 commit 09577ed
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions skimage/transform/_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,58 @@ class FundamentalMatrixTransform(_GeometricTransform):
params : (3, 3) array
Fundamental matrix.
Examples
--------
>>> import numpy as np
>>> import skimage as ski
>>> tform_matrix = ski.transform.FundamentalMatrixTransform()
Define source and destination points:
>>> src = np.array([1.839035, 1.924743,
... 0.543582, 0.375221,
... 0.473240, 0.142522,
... 0.964910, 0.598376,
... 0.102388, 0.140092,
... 15.994343, 9.622164,
... 0.285901, 0.430055,
... 0.091150, 0.254594]).reshape(-1, 2)
>>> dst = np.array([1.002114, 1.129644,
... 1.521742, 1.846002,
... 1.084332, 0.275134,
... 0.293328, 0.588992,
... 0.839509, 0.087290,
... 1.779735, 1.116857,
... 0.878616, 0.602447,
... 0.642616, 1.028681]).reshape(-1, 2)
Estimate the transformation matrix:
>>> tform_matrix.estimate(src, dst)
True
>>> tform_matrix.params
array([[-0.2178588368, 0.4192819131, -0.0343074756],
[-0.0717941428, 0.0451643229, 0.0216072614],
[ 0.2480621133, -0.4294781423, 0.0221019139]])
Compute the Sampson distance:
>>> tform_matrix.residuals(src, dst)
array([0.0053886022, 0.0052610069, 0.086897007 , 0.0185053395,
0.0941825909, 0.0018596663, 0.0616048944, 0.0265513581])
Apply inverse transformation:
>>> tform_matrix.inverse(dst)
array([[-0.0513590998, 0.0417097392, 0.0121304255],
[-0.2159949601, 0.2919341852, 0.0097818351],
[-0.0079222047, 0.0375888939, -0.0091538874],
[ 0.1418718406, -0.2798895924, 0.0247650748],
[ 0.0589007483, -0.073544809 , -0.0048134227],
[-0.2198526747, 0.3671746435, -0.01482408 ],
[ 0.0133956875, -0.0338812341, 0.0049760468],
[ 0.0342092683, -0.1135811955, 0.0222823604]])
"""

def __init__(self, matrix=None, *, dimensionality=2):
Expand Down

0 comments on commit 09577ed

Please sign in to comment.