transform
Functions to computing and working with transformations between point clouds
apply_transform(src, transform, shift)
Apply a transformation to a set of points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src |
NDArray[floating]
|
The points to transform. Should have shape (npoints, ndim). |
required |
transform |
NDArray[floating]
|
The transformation matrix. Should have shape (ndim, ndim). |
required |
shift |
NDArray[floating]
|
The shift to apply after the affine tranrform. Should have shape (ndim,). |
required |
Returns:
Name | Type | Description |
---|---|---|
transformed |
NDArray[floating]
|
The transformed points. Has the same shape as src. |
Raises:
Type | Description |
---|---|
ValueError
|
If src is not a 2d array. If one of src's axis is not of size ndim. If affine and shift have inconsistent shapes. |
Source code in megham/transform.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
decompose_affine(affine)
Decompose an affine transformation into its components. This decomposetion treats the affine matrix as: rotation * shear * scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
affine |
NDArray[floating]
|
The (ndim, ndim) affine transformation matrix. |
required |
Returns:
Name | Type | Description |
---|---|---|
scale |
NDArray[floating]
|
The (ndim,) array of scale parameters. |
shear |
NDArray[floating]
|
The (ndim*(ndim - 1)/2,) array of shear parameters. |
rot |
NDArray[floating]
|
The (ndim, ndim) rotation matrix. If ndim is 2 or 3 then decompose_rotation can be used to get euler angles. |
Raises:
Type | Description |
---|---|
ValueError
|
If affine is not ndim by ndim. |
Source code in megham/transform.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
decompose_rotation(rotation)
Decompose a rotation matrix into its xyz rotation angles. This currently won't work on anything higher than 3 dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rotation |
NDArray[floating]
|
The (ndim, ndim) rotation matrix. |
required |
Returns:
Name | Type | Description |
---|---|---|
angles |
NDArray[floating]
|
The rotation angles in radians. If the input is 3d then this has 3 angles in xyz order, if 2d it just has one. |
Raises:
Type | Description |
---|---|
ValueError
|
If affine is not ndim by ndim. If ndim is not 2 or 3. |
Source code in megham/transform.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
get_affine(src, dst, weights=None, center_dst=True, force_svd=False, **kwargs)
Get affine transformation between two point clouds. It is assumed that the point clouds have the same registration, ie. src[i] corresponds to dst[i].
Transformation is dst = src@affine + shift.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src |
NDArray[floating]
|
A (npoints, ndim) array of source points. |
required |
dst |
NDArray[floating]
|
A (npoints, ndim) array of destination points. |
required |
weights |
Optional[NDArray[floating]]
|
(npoints,) array of weights to use. If provided a weighted least squares is done instead of an SVD. |
None
|
center_dst |
bool
|
If True, dst will be recentered at the origin before computing transformation. This is done with get_shift, but weights will not be used if provided. |
True
|
force_svd |
bool
|
If True the SVD is used even if there are a small number of points or weights are present. |
False
|
**kwargs |
Arguments to pass to get_shift. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
affine |
NDArray[floating]
|
The (ndim, ndim) transformation matrix. |
shift |
NDArray[floating]
|
The (ndim,) shift to apply after transformation. |
Raises:
Type | Description |
---|---|
ValueError
|
If the input point clouds have different shapes. If the input point clouds don't have enough points. |
Source code in megham/transform.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
get_rigid(src, dst, center_dst=True, **kwargs)
Get rigid transformation between two point clouds. It is assumed that the point clouds have the same registration, ie. src[i] corresponds to dst[i].
Transformation is dst = src@rot + shift.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src |
NDArray[floating]
|
A (npoints, ndim) array of source points. |
required |
dst |
NDArray[floating]
|
A (npoints, ndim) array of destination points. |
required |
center_dst |
bool
|
If True, dst will be recentered at the origin before computing transformation. This is done with get_shift, but weights will not be used if provided. |
True
|
**kwargs |
Arguments to pass to get_shift. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
rotation |
NDArray[floating]
|
The (ndim, ndim) rotation matrix. |
shift |
NDArray[floating]
|
The (ndim,) shift to apply after transformation. If point are in col basis will be returned as a column vector. |
Raises:
Type | Description |
---|---|
ValueError
|
If the input point clouds have different shapes. If the input point clouds don't have enough points. |
Source code in megham/transform.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
get_shift(src, dst, method='median', weights=None)
Get shift between two point clouds. Shift can be applied as dst = src + shift.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src |
NDArray[floating]
|
A (ndim, npoints) array of source points. |
required |
dst |
NDArray[floating]
|
Nominally a (ndim, npoints) array of destination points, but really any array broadcastable with src is accepted. Some useful options are: * np.zeros(1) to align with the origin * A (ndim,) array to align with an arbitrary point |
required |
method |
str
|
Method to use to align points. Current accepted values are: 'median' and 'mean' |
'median'
|
weights |
Optional[NDArray[floating]]
|
(npoints,) array of weights to use. If provided and method is 'mean' then a weighted average is used. If method is median this is not currently used. |
None
|
Returns:
Name | Type | Description |
---|---|---|
shift |
NDArray[floating]
|
The (ndim,) shift to apply after transformation. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid method is provided |
Source code in megham/transform.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|