elektronn2.data.transformations module¶
-
elektronn2.data.transformations.
warp_slice
(img, ps, M, target=None, target_ps=None, target_vec_ix=None, target_discrete_ix=None, last_ch_max_interp=False, ksize=0.5)[source]¶ Cuts a warped slice out of the input image and out of the target image. Warping is applied by multiplying the original source coordinates with the inverse of the homogeneous (forward) transformation matrix
M
.“Source coordinates” (
src_coords
) signify the coordinates of voxels inimg
andtarget
that are used to compose their respective warped versions. The idea here is that not the images themselves, but the coordinates from where they are read are warped. his allows for much higher efficiency for large image volumes because we don’t have to calculate the expensive warping transform for the whole image, but only for the voxels that we eventually want to use for the new warped image. The transformed coordinates usually don’t align to the discrete voxel grids of the original images (meaning they are not integers), so the new voxel values are obtained by linear interpolation.Parameters: - img (np.ndarray) – Image array in shape
(f, z, x, y)
- ps (tuple) – (spatial only) Patch size
(z, x, y)
(spatial shape of the neural network’s input node) - M (np.ndarray) – Forward warping tansformation matrix (4x4). Must contain translations in source and target array.
- target (np.ndarray or None) – Optional target array to be extracted in the same way.
- target_ps (tuple) – Patch size for the
target
array. - target_vec_ix (list) – List of triples that denote vector value parts in the target array. E.g. [(0,1,2), (4,5,6)] denotes two vector fields, separated by a scalar field in channel 3.
- last_ch_max_interp (bool) –
- ksize (float) –
Returns: - img_new (np.ndarray) – Warped input image slice
- target_new (np.ndarray or None) – Warped target image slice
or
None
, iftarget is None
.
- img (np.ndarray) – Image array in shape
-
elektronn2.data.transformations.
get_tracing_slice
(img, ps, pos, z_shift=0, aniso_factor=2, sample_aniso=True, gamma=0, scale_factor=1.0, direction_iso=None, target=None, target_ps=None, target_vec_ix=None, target_discrete_ix=None, rng=None, last_ch_max_interp=False)[source]¶
-
exception
elektronn2.data.transformations.
WarpingOOBError
(*args, **kwargs)[source]¶ Bases:
exceptions.ValueError
-
class
elektronn2.data.transformations.
Transform
(M, position_l=None, aniso_factor=2)[source]¶ Bases:
object
-
M_lin
¶
-
M_lin_inv
¶
-
-
elektronn2.data.transformations.
get_warped_slice
(img, ps, aniso_factor=2, sample_aniso=True, warp_amount=1.0, lock_z=True, no_x_flip=False, perspective=False, target=None, target_ps=None, target_vec_ix=None, target_discrete_ix=None, rng=None)[source]¶ (Wraps
elektronn2.data.transformations.warp_slice()
)Generates the warping transformation parameters and composes them into a single 4D homogeneous transformation matrix
M
. Then this transformation is applied toimg
andtarget
in thewarp_slice()
function and the transformed input and target image are returned.Parameters: - img (np.array) – Input image
- ps (np.array) – Patch size (spatial shape of the neural network’s input node)
- aniso_factor (float) – Anisotropy factor that determines an additional scaling in
z
direction. - sample_aniso (bool) – Scale coordinates by
1 / aniso_factor
while warping. - warp_amount (float) – Strength of the random warping transformation. A lower
warp_amount
will lead to less distorted images. - lock_z (bool) – Exclude
z
coordinates from the random warping transformations. - no_x_flip (bool) – Don’t flip
x
axis during random warping. - perspective (bool) – Apply perspective transformations (in addition to affine ones).
- target (np.array) – Target image
- target_ps (np.array) – Target patch size
- target_vec_ix –
- target_discrete_ix –
- rng (np.random.mtrand.RandomState) – Random number generator state (obtainable by
np.random.RandomState()
). Passing a known state makes the random transformations reproducible.
Returns: - img_new (np.ndarray) – (Warped) input image slice
- target_new (np.ndarray) – (Warped) target slice