seidart.routines.volumebuilder module

class seidart.routines.volumebuilder.VolumeBuilder(files, locations, power=1.0, plane='yz')

Bases: object

Build a 3D labeled volume from a set of 2D images lying in a given plane (xy, yz, xz) and located at specific coordinates along the remaining axis.

Conventions

  • Internal 3D layout is (nx, ny, nz), corresponding to (x, y, z).

  • User provides ‘locations’ as 1-based slice indices along the orthogonal axis:

    plane=’xy’ -> locations are z-slices in [1..nz] plane=’yz’ -> locations are x-slices in [1..nx] plane=’xz’ -> locations are y-slices in [1..ny]

  • PNG images are assumed to be in (ny, nx, 3) pixel layout (row=y, col=x).

interpolate_distance_transform(image1, image2, t, spacing=(1.0, 1.0))

Interpolate between two 2D labeled slices using signed distance transforms.

Parameters:
  • slice_A ((H, W) int arrays) – Label images at positions z=0 and z=1.

  • slice_B ((H, W) int arrays) – Label images at positions z=0 and z=1.

  • t (float in [0, 1]) – Interpolation parameter; 0 -> slice_A, 1 -> slice_B.

  • spacing (tuple(float, float)) – Pixel spacing (dy, dx) for anisotropic grids, passed to EDT.

Returns:

out – Interpolated label image at position t.

Return type:

(H, W) int array

plot_scatter(label=None, rgb=None, dx=1.0, dy=1.0, dz=1.0, stride=1)

Plot a subset of voxels as a 3D scatter for a given label or RGB.

Parameters:
  • label (int or None) – Integer label to plot. If None, ‘rgb’ must be given.

  • rgb (tuple or None) – (R,G,B) color to plot. If None, ‘label’ must be given.

  • dx (float) – Physical spacing in x, y, z directions.

  • dy (float) – Physical spacing in x, y, z directions.

  • dz (float) – Physical spacing in x, y, z directions.

  • stride (int) – Subsampling step along each axis to reduce plotted points.

plot_slice(label=None, rgb=None, ix=None, iy=None, iz=None, dx=1.0, dy=1.0, dz=1.0, figure_size=(6, 6), cmap='tab20')

Plot orthogonal slices (x=const, y=const, z=const) through the 3D label volume.

Parameters:
  • label (int or None) – Integer label to highlight. If None and rgb is given, label is inferred from rgb. If both are None, all labels are shown.

  • rgb (tuple or None) – (R,G,B) color to map to a label. Ignored if label is provided.

  • ix (int or None) – Slice indices along x, y, z. If None, mid-plane is used. Indices are 0-based (Python convention).

  • iy (int or None) – Slice indices along x, y, z. If None, mid-plane is used. Indices are 0-based (Python convention).

  • iz (int or None) – Slice indices along x, y, z. If None, mid-plane is used. Indices are 0-based (Python convention).

  • dx (float) – Physical spacing in x, y, z directions (used only for axis ticks).

  • dy (float) – Physical spacing in x, y, z directions (used only for axis ticks).

  • dz (float) – Physical spacing in x, y, z directions (used only for axis ticks).

  • cmap (str) – Matplotlib colormap for imshow.

plot_voxels(label=None, rgb=None, dx=1.0, dy=1.0, dz=1.0, stride=1)

Plot a 3D voxel volume for a given label or RGB, downsampled.

Parameters:
  • label (int or None) – Integer label to plot. If None, ‘rgb’ must be given.

  • rgb (tuple or None) – (R,G,B) color to plot. If None, ‘label’ must be given.

  • dx (float) – Physical spacing in x, y, z directions.

  • dy (float) – Physical spacing in x, y, z directions.

  • dz (float) – Physical spacing in x, y, z directions.

  • stride (int) – Subsampling step; >1 reduces number of voxels drawn.