Repository navigation
This release modernizes the package. Apart from the corrections listed below, results of registrations and transformations are unchanged: they are verified bit for bit against 0.2.8.
License
- pystackreg is now distributed under the GNU General Public License, version 3 or later, the license under which TurboReg and StackReg are distributed by their author. Versions up to 0.2.8 remain under the terms they were published with. See
NOTICE.
Added
- Parallel processing:
register_stack(),transform_stack()andregister_transform_stack()acceptn_jobs(number of threads;-1uses all CPUs). The native code releases the GIL, so threads are used and no data are copied between processes. Parallel results are identical to sequential results for all reference modes, including"previous"(#14, #17, #33). transform_stack()andregister_transform_stack()acceptout: a preallocated array of another dtype (integer dtypes are rounded and clipped), anumpy.memmap, or the input itself for in-place operation (#28)StackReg.transform_points()applies a transformation to point coordinates, also for the bilinear transformation (#42)pystackreg.util.max_displacement()measures the amplitude of transformations, e.g. to detect implausible registration results (#41)transform_stack()acceptsverboseandprogress_callback;register_transform_stack()acceptssuppress_axis_warning.- Type annotations (
py.typed), support for free-threaded CPython builds. - Validation suite; the documentation reports a comparison with the original TurboReg.
Changed
- Python 3.10 or newer is required; Python 3.10 - 3.15 are tested. Wheels are built against NumPy 2 and run with NumPy >= 1.22.
- Memory use of stack functions is much lower (#28) the time-axis check, the moving average and
transform_stack()no longer create temporary copies of the whole stack. transform()is about three times faster (1.6 times for the bilinear transformation); it no longer computes image pyramids and gradients that only the registration needs. The speed ofregister()is unchanged.- Binary wheels are no longer built for 32-bit platforms (Linux i686, Windows win32); wheels for Linux aarch64 and macOS x86-64 are added.
- Progress bars use
tqdm.auto(#11) - Invalid arguments raise
ValueError,TypeErrororRuntimeErrorwith specific messages instead of a bareException. - Images containing NaN or infinite values are rejected by
register()andregister_stack()with aValueError. Previously such images silently produced an identity transformation. - Images smaller than 3 x 3 pixels, empty stacks, non-finite transformation matrices and matrices of the wrong shape are rejected with a
ValueError. Previously these cases read out-of-bounds memory or crashed. - The moving average (
moving_average> 1) of floating-point stacks is computed in double precision, so results for such stacks can differ in the last digits from 0.2.8. Integer stacks are unaffected. - Compiled with
-ffp-contract=off: results no longer depend on whether the CPU architecture fuses multiply-add operations (affects arm64 builds in the last bits). - Project metadata moved to
pyproject.toml; development uses Ruff, mypy and pytest.
Fixed
reference="previous"combined withmoving_average> 1 registered the first frame against the last frame of the stack, which shifted the
whole registered stack.moving_average> 1 gave wrong results foraxisother than 0 (util.running_mean()ignored the axis when taking differences).- Memory leak in the extension module: every call to
register()leaked the three returned arrays (about 430 bytes). - Crash (NULL pointer dereference) when an image could not be converted to floating point, e.g. for complex data.
- Out-of-bounds reads for images with a side of one or two pixels.
- Undefined behavior (float-to-int conversion of NaN/out-of-range values) in the registration of constant images and in
transform()with extreme matrices; conversions now follow the semantics of the Java original. get_matrix()before a registration raised an unrelatedTypeError.- Images with a side shorter than 24 pixels were not registered reliably with the scaled-rotation and affine transformations: the registration used a value that was never set, so the result depended on the contents of memory and was usually the identity. Such images are now registered. This differs from TurboReg, which returns the identity in this case; results for larger images are unchanged.
Removed
- Support for Python < 3.10 and the Python 2 code paths of the extension.