linumpy.registration.manual#

Manual image registration and correction GUI for z-slice stacks.

Attributes#

Classes#

ManualImageCorrection

Manual image correction using a graphical user interface.

Functions#

apply_transform(ty, tx, theta, coordinates)

Apply transformation to coordinates.

apply_scaling(data, vmin, vmax)

Rescale image intensities from (vmin, vmax) to (0.0, 1.0).

transform_and_rescale_slice(slice, ty, tx, theta, ...)

Transform and rescale a 2D slice.

Module Contents#

linumpy.registration.manual.PREV_REF_LABEL = 'Previous slice as reference'[source]#
linumpy.registration.manual.NEXT_REF_LABEL = 'Next slice as reference'[source]#
linumpy.registration.manual.NO_REF_LABEL = 'No reference slice'[source]#
class linumpy.registration.manual.ManualImageCorrection(data, resolution, downsample_factor, transforms=None, custom_ranges=None)[source]#

Manual image correction using a graphical user interface.

Corrections include independent translation and rotation of each z-slice as well as image intensities rescaling per z-slice.

Parameters:
  • data (ndarray of shape (nz, ny, nx)) – Stack of images, where images are stacked along the first axis (z).

  • resolution (3-tuple) – Resolution of the dataset (rz, ry, rx).

  • downsample_factor (int) – Factor by which the full resolution images are downscaled prior to rendering. Tradeoff between image quality and interactivity of the GUI. Does not influence the resolution of the corrected image.

  • transforms (ndarray (nz, 3), optional) – Transform for each slice where each array (3,) contains a translation (ty, tx) and a rotation (theta).

  • custom_ranges (ndarray (nz, 2), optional) – Intensities for rescaling each slice. One (vmin, vmax) per slice.

downsample[source]#
max_z[source]#
image_interpolator[source]#
grid_coordinates[source]#
ref_z_mode = 'No reference slice'[source]#
current_x[source]#
current_y[source]#
current_z = 0[source]#
axim_a[source]#
axim_b[source]#
axim_c[source]#
scalebar[source]#
s_offset_a[source]#
s_offset_b[source]#
s_current_z[source]#
s_current_y[source]#
s_current_x[source]#
s_theta[source]#
radio_buttons[source]#
start()[source]#

Start GUI.

Returns:

return – True when the window closes.

Return type:

bool

on_change_scaling(scaling_range)[source]#

Update intensity rescaling for the current z-slice.

Parameters:

scaling_range (tuple)

Return type:

None

on_change_z(val)[source]#

Update current z-slice index.

Parameters:

val (float)

Return type:

None

on_change_y(val)[source]#

Update current y-plane index.

Parameters:

val (float)

Return type:

None

on_change_x(val)[source]#

Update current x-plane index.

Parameters:

val (float)

Return type:

None

on_change_offset_a(val)[source]#

Update y-translation for the current z-slice.

Parameters:

val (float)

Return type:

None

on_change_offset_b(val)[source]#

Update x-translation for the current z-slice.

Parameters:

val (float)

Return type:

None

on_change_theta(val)[source]#

Update rotation angle for the current z-slice.

Parameters:

val (float)

Return type:

None

on_change_ref_z(label)[source]#

Update reference z-slice mode.

Parameters:

label (str | None)

Return type:

None

transform_coordinates(coordinates, z=None)[source]#

Apply the stored transform to a set of grid coordinates.

Parameters:
Return type:

numpy.ndarray

apply_scaling(data, z=None)[source]#

Rescale slice intensities using the stored per-slice ranges.

Parameters:
Return type:

numpy.ndarray

draw_cursor(data)[source]#

Draw a cursor line at the current z position on a view.

Parameters:

data (numpy.ndarray)

Return type:

numpy.ndarray

get_view_a()[source]#

Return the YZ view (x-plane) as a transformed, scaled image.

Return type:

numpy.ndarray

get_view_b()[source]#

Return the XZ view (y-plane) as a transformed, scaled image.

Return type:

numpy.ndarray

get_view_c()[source]#

Return the XY view (z-slice) as a transformed, scaled RGB image.

Return type:

numpy.ndarray

save_results(filename)[source]#

Save resulting corrections to npz file.

Parameters:

filename (string or Path) – Output filename.

Return type:

None

linumpy.registration.manual.apply_transform(ty, tx, theta, coordinates)[source]#

Apply transformation to coordinates.

Coordinates are expected to be of shape (nz, ny, nx, 3), with each coordinate given in the order (z, y, x).

Parameters:
  • ty (float or ndarray of shape (nz,)) – Translation along y axis.

  • tx (float or ndarray of shape (nz,)) – Translation along x axis.

  • theta (float or ndarray of shape (nz,)) – Rotation around z axis in radians. The center of rotation is the center of the image.

  • coordinates (ndarray of shape (nz, ny, nx, 3)) – Input grid coordinates in (z, y, x) order.

Returns:

coordinates – Transformed coordinates.

Return type:

ndarray (nz, ny, nx, 3)

linumpy.registration.manual.apply_scaling(data, vmin, vmax)[source]#

Rescale image intensities from (vmin, vmax) to (0.0, 1.0).

Values outside the range (vmin, vmax) are clipped.

Rescaling can be performed with a single range for the whole image or with a different range for each ROW. In the case, the first dimension of data should correspond to the number of elements in vmin, vmax.

Parameters:
  • data (ndarray) – The intensities to rescale.

  • vmin (float or ndarray of shape (data.shape[0],)) – Minimum value. Will be worth 0 after rescaling.

  • vmax (float or ndarray of shape (data.shape[0],)) – Maximum value. Will be worth 1 after rescaling.

Returns:

data – Recaled intensities.

Return type:

ndarray

linumpy.registration.manual.transform_and_rescale_slice(slice, ty, tx, theta, vmin, vmax)[source]#

Transform and rescale a 2D slice.

Transform consists of a translation (ty, tx) and a rotation theta. Rescaling clips intensities to (vmin, vmax) and rescales the resulting values to the range (0, 1).

Parameters:
  • slice (ndarray of shape (ny, nx)) – Slice to process.

  • ty (float) – Translation along y axis (first axis).

  • tx (float) – Translation along x axis (second axis).

  • theta (float) – Rotation in radians.

  • vmin (float) – Minimum value for rescaling.

  • vmax (float) – Maximum value for rescaling.

Returns:

slice – Processed slice.

Return type:

ndarray of shape (ny, nx)