cpd
Module for performing coherent point drift
Callback
Bases: Protocol
Callback idea shamelessly stolen from pycpd.
Source code in megham/registration/cpd.py
17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
compute_P(source, target, var, w)
Compute matrix of probabilities of matches between points in source and target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
NDArray[floating]
|
The set of source points to be mapped onto the target points. Nominally when you run this it will be the source points transformed to line up with target. Should have shape (nsrcpoints, ndim). |
required |
target
|
NDArray[floating]
|
The set of target points to be mapped onto. Should have shape (ntrgpoints, ndim). |
required |
var
|
NDArray[floating]
|
The variance of the gaussian mixture model. Should have shape (ndim,). |
required |
w
|
float
|
The weight of the uniform distrubution. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
P |
NDArray[floating]
|
Probability matrix of matches between the source and target points. P[i,j] is the probability that source[i] corresponds to target[j]. Has shape (nsrcpoints, ntrgpoints). |
Source code in megham/registration/cpd.py
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
cpd(source, target, w=0.0, eps=1e-10, max_iters=500, callback=dummy_callback, method='affine')
Compute the CPD. This is just a wrapper around joint_cpd that puts everything into one dim_group. See the docstring of joint_cpd for details on the parameters and returns.
See https://arxiv.org/abs/0905.2635 for details on the base CPD algorithm.
Source code in megham/registration/cpd.py
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 |
|
joint_cpd(source, target, dim_groups=None, w=0.0, eps=0.001, max_iters=500, callback=dummy_callback, method='affine')
Compute the joint CPD.
This is an extension of the base CPD algorithm that allows you to fit for transforms that treat groups of dimensions seperately but use a jointly computed probability matrix and variance. This is useful in cases where you have information about a set of points that is correlated but in a different basis so you want to avoid degrees of freedom that mix the disprate baseis. For example if you have a set of points where you have both spatial information as well as some non-spatial scalar associated with each point (ie: frequency) you can use this to compute a registration that considers these jointly but transforms them seperately to avoid a scenario where you have a rotation between a spatial and a non-spatial dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
NDArray[floating]
|
The set of source points to be mapped onto the target points. Should have shape (nsrcpoints, ndim). |
required |
target
|
NDArray[floating]
|
The set of target points to be mapped onto. Should have shape (ntrgpoints, ndim). |
required |
dim_groups
|
Optional[Sequence[Sequence[int] | NDArray[int_]]]
|
Which dimensions should be transformed together. Each element in this sequence should be a sequence of array of ints that correspond to the columns of source and target that are transformed together. Any columns that are not included here will not be transformed but will still be used when computing the probability and variance. None of the elements in this sequence can have overlap. If set to None all the dimensions will be transformed together. |
None
|
w
|
float
|
The weight of the uniform distrubution. Set higher to reduce sensitivity to noise and outliers at the expense of potentially worse performance. Should be in the range [0, 1), if not it will snap to one of the bounds. |
0.0
|
eps
|
float
|
The convergence criteria. When the change in the objective function is less than or equal to this we stop. |
1e-10
|
max_iters
|
int
|
The maximum number of iterations to run for. |
500
|
callback
|
Callback
|
Function that runs once per iteration, can be used to visualize the match process. See the Callback Protocol for details on the expected signature. |
dummy_callback
|
method
|
str
|
The type of transformation to compute. Acceptable values are: affine, rigid. If any other value is passed then transform will be the identity. |
'affine'
|
Returns:
Name | Type | Description |
---|---|---|
transform |
NDArray[floating]
|
The transform transformation that takes source to target. Apply using megham.transform.apply_transform. Has shape (ndim, ndim). |
shift |
NDArray[floating]
|
The transformation that takes source to target after transform is applied. Apply using megham.transform.apply_transform. Has shape (ndim,). |
transformed |
NDArray[floating]
|
Source transformed to align with target. Has shape (nsrcpoints, ndim). |
P |
NDArray[floating]
|
Probability matrix of matches between the source and target points. P[i,j] is the probability that source[i] corresponds to target[j]. Has shape (nsrcpoints, ntrgpoints). |
Raises:
Type | Description |
---|---|
ValueError
|
If source and target don't share ndim. If dim_groups has repeated dimensions or invalid dimensions. |
Source code in megham/registration/cpd.py
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 225 226 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 271 272 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 313 314 315 |
|
solve_transform(source, target, P, dim_groups, cur_var, method='affine')
Solve for the transformation at each iteration of CPD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
NDArray[floating]
|
The set of source points to be mapped onto the target points. Should have shape (nsrcpoints, ndim). |
required |
target
|
NDArray[floating]
|
The set of target points to be mapped onto. Should have shape (ntrgpoints, ndim). |
required |
P
|
NDArray[floating]
|
Probability matrix of matches between the source and target points. |
required |
dim_groups
|
Sequence[NDArray[int_]]
|
Which dimensions should be transformed together. |
required |
cur_var
|
float
|
The current mixture model variance. |
required |
method
|
str
|
The type of transformation to compute. Acceptable values are: affine, rigid. If any other value is passed then transform will be the identity. |
'affine'
|
Returns:
Name | Type | Description |
---|---|---|
transform |
NDArray[floating]
|
Transformation between source and target. |
shift |
NDArray[floating]
|
Shift to be applied after the affine transformation. |
var |
NDArray[floating]
|
Current variance of the mixture model. |
err |
float
|
Current value of the error function. |
Source code in megham/registration/cpd.py
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 135 136 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 |
|