foa3d.pipeline

foa3d.pipeline.analyze_fibers(fbr_slc, cfg, out_rng, pad_rng, ts_msk=None, _fa=False)

Analyze 3D fiber orientations exploiting a Frangi-filter-based unsupervised enhancement of tubular structures.

Parameters
  • fbr_slc (numpy.ndarray (axis order=(Z,Y,X))) – fiber image slice

  • cfg (dict) –

    Frangi filter configuration

    alpha: float

    plate-like score sensitivity

    beta: float

    blob-like score sensitivity

    gamma: float

    background score sensitivity

    scales_px: numpy.ndarray (dtype=float)

    Frangi filter scales [px]

    scales_um: numpy.ndarray (dtype=float)

    Frangi filter scales [μm]

    smooth_sd: numpy.ndarray (shape=(3,), dtype=int)

    3D standard deviation of the smoothing Gaussian filter [px]

    px_sz: numpy.ndarray (shape=(3,), dtype=float)

    pixel size [μm]

    fb_thr: float or str

    image thresholding applied to the Frangi filter response

    msk_bc: bool

    if True, mask neuronal bodies within the optionally provided channel

    hsv_cmap: bool

    generate HSV colormap of 3D fiber orientations

    exp_all: bool

    export all images

    rsz: numpy.ndarray (shape=(3,), dtype=float)

    3D image resize ratio

    ram: float

    maximum RAM available to the Frangi filter stage [B]

    jobs: int

    number of parallel jobs (threads) used by the Frangi filter stage

    batch: int

    slice batch size

    slc_shp: numpy.ndarray (shape=(3,), dtype=int)

    shape of the basic image slices analyzed using parallel threads [px]

    ovlp: int

    overlapping range between image slices along each axis [px]

    tot_slc: int

    total number of image slices

    z_out: NumPy slice object

    output z-range

  • out_rng (NumPy slice object) – output range

  • pad_rng (numpy.ndarray (axis order=(Z,Y,X))) – image padding range

  • ts_msk (numpy.ndarray (dtype=bool)) – tissue reconstruction binary mask

  • _fa (bool) – compute fractional anisotropy

Returns

out_slc

slice output dictionary

vec: numpy.ndarray (axis order=(Z,Y,X,C), dtype=float)

3D fiber orientation field

clr: numpy.ndarray (axis order=(Z,Y,X,C), dtype=uint8)

orientation colormap

fa: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

fractional anisotropy

frangi: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

Frangi-enhanced image slice (fiber probability image)

iso: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

isotropic fiber image slice

ts_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

tissue mask slice

fbr_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

fiber mask slice

Return type

dict

foa3d.pipeline.frangi_analysis(rng, in_img, out_img, cfg, t_start, _fa=False)

Conduct a Frangi-based fiber orientation analysis on basic slices selected from the whole microscopy volume image.

Parameters
  • rng (dict) –

    in: np.ndarray

    3D input slice range [px]

    pad: np.ndarray

    3D slice padding range [px]

    out: np.ndarray

    3D output slice range [px]

    bc: np.ndarray

    (optional) brain cell soma slice range

  • in_img (dict) –

    input image dictionary

    data: NumPy memory-map object (axis order=(Z,Y,X) or (Z,Y,X,C) or (Z,C,Y,X))

    3D microscopy image

    ch_ax: int

    RGB image channel axis (either 1, 3, or None for grayscale images)

    ts_msk: numpy.ndarray (dtype=bool)

    tissue reconstruction binary mask

    fb_ch: int

    neuronal fibers channel

    bc_ch: int

    brain cell soma channel

    msk_bc: bool

    if True, mask neuronal bodies within the optionally provided channel

    psf_fwhm: numpy.ndarray (shape=(3,), dtype=float)

    3D FWHM of the PSF [μm]

    px_sz: numpy.ndarray (shape=(3,), dtype=float)

    pixel size [μm]

    path: str

    path to the 3D microscopy image

    name: str

    name of the 3D microscopy image

    fmt: str

    format of the 3D microscopy image

    is_tiled: bool

    True for tiled reconstructions aligned using ZetaStitcher

    is_vec: bool

    vector field flag

    shape: numpy.ndarray (shape=(3,), dtype=int)

    total image shape

    shape_um: numpy.ndarray (shape=(3,), dtype=float)

    total image shape [μm]

    item_sz: int

    image item size [B]

  • out_img (dict) –

    output image dictionary

    vec: NumPy memory-map object (axis order=(Z,Y,X,C), dtype=float32)

    fiber orientation vector field

    clr: NumPy memory-map object (axis order=(Z,Y,X,C), dtype=uint8)

    orientation colormap image

    fa: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    fractional anisotropy image

    frangi: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    Frangi-enhanced image (fiber probability image)

    iso: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    isotropic fiber image

    fbr_msk: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    fiber mask image

    bc_msk: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    soma mask image

    px_sz: numpy.ndarray (shape=(3,), dtype=float)

    output pixel size [μm]

  • cfg (dict) –

    Frangi filter configuration

    alpha: float

    plate-like score sensitivity

    beta: float

    blob-like score sensitivity

    gamma: float

    background score sensitivity

    scales_px: numpy.ndarray (dtype=float)

    Frangi filter scales [px]

    scales_um: numpy.ndarray (dtype=float)

    Frangi filter scales [μm]

    smooth_sd: numpy.ndarray (shape=(3,), dtype=int)

    3D standard deviation of the smoothing Gaussian filter [px]

    px_sz: numpy.ndarray (shape=(3,), dtype=float)

    pixel size [μm]

    fb_thr: float or str

    image thresholding applied to the Frangi filter response

    msk_bc: bool

    if True, mask neuronal bodies within the optionally provided channel

    hsv_cmap: bool

    generate HSV colormap of 3D fiber orientations

    exp_all: bool

    export all images

    rsz: numpy.ndarray (shape=(3,), dtype=float)

    3D image resize ratio

    ram: float

    maximum RAM available to the Frangi filter stage [B]

    jobs: int

    number of parallel jobs (threads) used by the Frangi filter stage

    batch: int

    slice batch size

    slc_shp: numpy.ndarray (shape=(3,), dtype=int)

    shape of the basic image slices analyzed using parallel threads [px]

    ovlp: int

    overlapping range between image slices along each axis [px]

    tot_slc: int

    total number of image slices

    z_out: NumPy slice object

    output z-range

  • t_start (float) – start time [s]

  • _fa (bool) – compute fractional anisotropy

Return type

None

foa3d.pipeline.odf_analysis(fbr_vec, iso_fbr, px_sz, save_dirs, img_name, odf_scale_um, odf_norm, odf_deg=6, exp_all=False)

Estimate 3D fiber ODFs from basic orientation data chunks using parallel threads.

Parameters
  • fbr_vec (NumPy memory-map object (axis order=(Z,Y,X,C), dtype=float32)) – fiber orientation vector field

  • iso_fbr (NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)) – isotropic fiber image

  • px_sz (numpy.ndarray (shape=(3,), dtype=float)) – adjusted isotropic pixel size [μm]

  • save_dirs (dict) – saving directories (‘frangi’: Frangi filter, ‘odf’: ODF analysis)

  • img_name (str) – name of the 3D microscopy image

  • odf_scale_um (float) – fiber ODF resolution (super-voxel side [μm])

  • odf_norm (numpy.ndarray (dtype: float)) – 2D array of spherical harmonic normalization factors

  • odf_deg (int) – degrees of the spherical harmonic series expansion

  • exp_all (bool) – export all images

Return type

None

foa3d.pipeline.parallel_frangi_over_slices(cli_args, save_dirs, in_img)

Apply 3D Frangi filtering to basic TPFM image slices using parallel threads.

Parameters
  • cli_args (see ArgumentParser.parse_args) – populated namespace of command line arguments

  • save_dirs (dict) –

    saving directories

    frangi: Frangi filter

    odf: ODF analysis

    tmp: temporary data

  • in_img (dict) –

    input image dictionary

    data: NumPy memory-map object (axis order=(Z,Y,X) or (Z,Y,X,C) or (Z,C,Y,X))

    3D microscopy image

    ch_ax: int

    RGB image channel axis (either 1, 3, or None for grayscale images)

    ts_msk: numpy.ndarray (dtype=bool)

    tissue reconstruction binary mask

    fb_ch: int

    neuronal fibers channel

    bc_ch: int

    brain cell soma channel

    msk_bc: bool

    if True, mask neuronal bodies within the optionally provided channel

    psf_fwhm: numpy.ndarray (shape=(3,), dtype=float)

    3D FWHM of the PSF [μm]

    px_sz: numpy.ndarray (shape=(3,), dtype=float)

    pixel size [μm]

    path: str

    path to the 3D microscopy image

    name: str

    name of the 3D microscopy image

    fmt: str

    format of the 3D microscopy image

    is_tiled: bool

    True for tiled reconstructions aligned using ZetaStitcher

    is_vec: bool

    vector field flag

    shape: numpy.ndarray (shape=(3,), dtype=int)

    total image shape

    shape_um: numpy.ndarray (shape=(3,), dtype=float)

    total image shape [μm]

    item_sz: int

    image item size [B]

Returns

out_img

output image dictionary

vec: NumPy memory-map object (axis order=(Z,Y,X,C), dtype=float32)

fiber orientation vector field

clr: NumPy memory-map object (axis order=(Z,Y,X,C), dtype=uint8)

orientation colormap image

fa: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

fractional anisotropy image

frangi: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

Frangi-enhanced image (fiber probability image)

iso: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

isotropic fiber image

fbr_msk: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

fiber mask image

bc_msk: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

soma mask image

px_sz: numpy.ndarray (shape=(3,), dtype=float)

output pixel size [μm]

Return type

dict

foa3d.pipeline.parallel_odf_over_scales(cli_args, save_dirs, out_img, img_name)

Iterate over the required spatial scales and apply the parallel ODF analysis implemented in parallel_odf_on_slices().

Parameters
  • cli_args (see ArgumentParser.parse_args) – populated namespace of command line arguments

  • save_dirs (dict) –

    saving directories

    frangi: Frangi filter

    odf: ODF analysis

    tmp: temporary data

  • out_img (dict) –

    output image dictionary

    vec: NumPy memory-map object (axis order=(Z,Y,X,C), dtype=float32)

    fiber orientation vector field

    clr: NumPy memory-map object (axis order=(Z,Y,X,C), dtype=uint8)

    orientation colormap image

    fa: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    fractional anisotropy image

    frangi: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    Frangi-enhanced image (fiber probability image)

    iso: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    isotropic fiber image

    fbr_msk: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    fiber mask image

    bc_msk: NumPy memory-map object (axis order=(Z,Y,X), dtype=uint8)

    soma mask image

    px_sz: numpy.ndarray (shape=(3,), dtype=float)

    output pixel size [μm]

  • img_name (str) – name of the input volume image

Return type

None

foa3d.pipeline.reject_brain_cells(bc_slc, out_slc, rsz_ratio, out_rng, bc_thr='yen')

Suppress soma contribution using the optional image channel of neuronal bodies.

Parameters
  • bc_slc (numpy.ndarray (axis order=(Z,Y,X))) – brain cell soma image slice

  • out_slc (dict) –

    slice output dictionary

    vec: numpy.ndarray (axis order=(Z,Y,X,C), dtype=float)

    3D fiber orientation field

    clr: numpy.ndarray (axis order=(Z,Y,X,C), dtype=uint8)

    orientation colormap

    fa: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

    fractional anisotropy

    frangi: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

    Frangi-enhanced image slice (fiber probability image)

    iso: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

    isotropic fiber image slice

    ts_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

    tissue mask slice

    fbr_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

    fiber mask slice

  • rsz_ratio (numpy.ndarray (shape=(3,), dtype=float)) – 3D image resize ratio

  • out_rng (NumPy slice object) – output range

  • bc_thr (str) – thresholding method applied to the channel of brain cell bodies

Returns

out_slc

(masked) slice output dictionary

vec: numpy.ndarray (axis order=(Z,Y,X,C), dtype=float)

3D fiber orientation field

clr: numpy.ndarray (axis order=(Z,Y,X,C), dtype=uint8)

orientation colormap

fa: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

fractional anisotropy

frangi: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

Frangi-enhanced image slice (fiber probability image)

iso: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

isotropic fiber image slice

ts_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

tissue mask slice

fbr_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=uint8)

fiber mask slice

bc_msk: numpy.ndarray (axis order=(Z,Y,X), dtype=bool)

brain cell mask

Return type

dict