DeepD3 core
analysis
- class deepd3.core.analysis.ROI2D_Creator(dendrite_prediction, spine_prediction, threshold)
- clean(maxD, minS, dendrite_threshold=0.7)
Cleanes ROIs
- Parameters
maxD (int) – maximum distance to dendrite in px
minS (int) – minimum size of ROIs in px
dendrite_threshold (float, optional) – _description_. Defaults to 0.7.
- Returns
old ROI count, new ROI count
- Return type
tuple
- create(applyWatershed=False, maskSize=3, minDistance=3)
Creates 2D ROIs
- Parameters
applyWatershed (bool, optional) – Apply Watershed algorithm. Defaults to False.
maskSize (int, optional) – Size of the distance transform mask. Defaults to 3.
minDistance (int, optional) – Minimum distance between ROIs in Watershed algorithm. Defaults to 3.
- Returns
ROIs found
- Return type
int
- zSignal
- class deepd3.core.analysis.ROI3D_Creator(dendrite_prediction, spine_prediction, mode='floodfill', areaThreshold=0.25, peakThreshold=0.8, seedDelta=0.1, distanceToSeed=10, dimensions={'xy': 0.094, 'z': 0.5})
- create(minPx, maxPx, minPlanes, applyWatershed=False, dilation=0)
Create 3D ROIs
- Parameters
minPx (int) – only retain 3D ROIs containing at least minPx pixels
maxPx (int) – only retain 3D ROIs containing at most maxPx pixels
minPlanes (int) – only retain 3D ROIs spanning at least minPlanes planes
applyWatershed (bool, optional) – Apply watershed algorithm to divide ROIs. Defaults to False.
dilation (int, optional) – Dilate dendrite probability map. Defaults to 0.
- Returns
number of retained ROIs
- Return type
int
- log
- zSignal
- class deepd3.core.analysis.Stack(fn, pred_fn=None, dimensions={'xy': 0.094, 'z': 0.5})
- cleanDendrite(dendrite_threshold=0.7, min_dendrite_size=100)
Cleaning dendrite
- Parameters
dendrite_threshold (float, optional) – Dendrite probability threshold. Defaults to 0.7.
min_dendrite_size (int, optional) – Minimum dendrite size. Defaults to 100.
- Returns
Cleaned dendrite prediction map
- Return type
numpy.ndarray
- cleanDendrite3D(dendrite_threshold=0.7, min_dendrite_size=100, preview=False)
Cleaning dendrites in 3D
- Parameters
dendrite_threshold (float, optional) – Dendrite semantic segmentation threshold. Defaults to 0.7.
min_dendrite_size (int, optional) – Minimum dendrite size in px in 3D. Defaults to 100.
preview (bool, optional) – Enable preview option. Defaults to False.
- Returns
Cleaned dendrite
- Return type
numpy.ndarray
- cleanSpines(dendrite_threshold=0.7, dendrite_dilation_iterations=12, preview=False)
Cleaning spines in 2D
- Parameters
dendrite_threshold (float, optional) – Dendrite threshold for segmentation. Defaults to 0.7.
dendrite_dilation_iterations (int, optional) – Iterations to enlarge dendrite. Defaults to 12.
preview (bool, optional) – Enable preview option (not overwriting predictions). Defaults to False.
- Returns
cleaned spines stack
- Return type
numpy.ndarray
- closing(iterations=1, preview=False)
Closing operation on dendrite prediction map
- Parameters
iterations (int, optional) – Iterations of closing operation. Defaults to 1.
preview (bool, optional) – Enables preview mode. Defaults to False.
- Returns
cleaned dendrite map
- Return type
numpy.ndarray
- predictFourFold(model_fn, tile_size=128, inset_size=96, pad_op=<function mean>, zmin=None, zmax=None)
Similar to predictInset (single tile prediction), but with four-way correction
- Parameters
model_fn (str) – path to Tensorflow/Keras model
tile_size (int, optional) – Size of full tile. Defaults to 128.
inset_size (int, optional) – Size of tile inset (probability map to be kept). Defaults to 96.
pad_op (_type_, optional) – Padding operation. Defaults to np.mean.
zmin (_type_, optional) – Z-index minimum. Defaults to None.
zmax (_type_, optional) – Z-index maxmimum. Defaults to None.
- Returns
operation was successful
- Return type
bool
- predictInset(model_fn, tile_size=128, inset_size=96, pad_op=<function mean>, zmin=None, zmax=None, clean_dendrite=True, dendrite_threshold=0.7)
Predict inset
- Parameters
model_fn (str) – path to Tensorflow/Keras model
tile_size (int, optional) – Size of full tile. Defaults to 128.
inset_size (int, optional) – Size of tile inset (probability map to be kept). Defaults to 96.
pad_op (_type_, optional) – Padding operation. Defaults to np.mean.
zmin (_type_, optional) – Z-index minimum. Defaults to None.
zmax (_type_, optional) – Z-index maxmimum. Defaults to None.
clean_dendrite (bool, optional) – Cleaning dendrite. Defaults to True.
dendrite_threshold (float, optional) – Dendrite probability threshold. Defaults to 0.7.
- Returns
operation was successful
- Return type
bool
- predictWholeImage(model_fn)
Predict whole image, plane by plane
- Parameters
model_fn (str) – path to Tensorflow/Keras model file
- Returns
operation was successful
- Return type
bool
- tileSignal
- deepd3.core.analysis._distance_to_seed(seed, pos, delta_xy=1, delta_z=1)
Computes the euclidean distance between seed pixel and current position pos
- Parameters
seed (tuple) – seed pixel coordinates (x,y,z)
pos (tuple) – current position coordinates (x,y,z)
- Returns
euclidean distance between seed and current position
- Return type
float
- deepd3.core.analysis._get_sorted_seeds(stack, threshold=0.8)
Sort seeds according to their highest prediction value
- Parameters
stack (numpy ndarray) – The stack with the predictions
threshold (float, optional) – The threshold for being a seed pixel. Defaults to 0.8.
- Returns
seed coordinates sorted by prediction value
- Return type
numpy.ndarray
- deepd3.core.analysis._neighbours(x, y, z)
Generates 26-connected neighbours
- Parameters
x (int) – x-value
y (int) – y-value
z (int) – z-value
- Returns
neighbour indices of a given point (x,y,z)
- Return type
list
- deepd3.core.analysis.centroid3D(im)
Computes centroid from a 3D binary image
- Parameters
im (numpy.ndarray) – binary image
- Returns
centroid coordinates z,y,x
- Return type
tuple
- deepd3.core.analysis.centroids3D_from_labels(labels)
Computes the centroid for each label in an 3D stack containing image labels. 0 is background, 1…N are foreground labels. This function uses image moments to compute the centroid.
- Parameters
labels (numpy.ndarray) – ROI labeled image (0…N)
- Returns
Returns first-order moments, zero-order moments and covered planes
- Return type
tuple(numpy.ndarray, numpy.ndarray, numpy.ndarray)
- deepd3.core.analysis.cleanLabels(labels, rois_to_delete)
Cleans labels from label stack. Set labels in rois_to_delete to background.
- Parameters
labels ([type]) – [description]
rois_to_delete ([type]) – [description]
- Returns
[description]
- Return type
[type]
- deepd3.core.analysis.connected_components_3d(prediction, seeds, delta, threshold, distance, dimensions)
Computes connected components in 3D using various constraints. Each ROI is grown from a seed pixel. From there, in a 26-neighbour fashion more pixels are added iteratively. Each additional pixel needs to fulfill the following requirements:
The new pixel’s intensity needs to be in a given range relative to the seed intensity (delta)
The new pixel’s intensity needs to be above a given threshold
The new pixel’s position needs to be in the vicinity (distance) of the seed pixel
Each pixel can only be assigned to one ROI once.
- Parameters
prediction (numpy.ndarray) – prediction from deep neural network
seeds (numpy.ndarray) – seed pixels
delta (float) – difference to seed pixel intensity
threshold (float) – threshold for pixel intensity
distance (int or float) – maximum euclidean distance in microns to seed pixel
dimensions (dict(float, float)) – xy and z pitch in microns
- Returns
the labelled stack and the number of found ROIs
- Return type
tuple(labels, N)
- deepd3.core.analysis.getROIsizes(labels)
Get the ROI size for each label with one single stack pass
- Parameters
labels (numpy.ndarray) – label map
- Returns
the size of each ROI area
- Return type
numpy.ndarray
- deepd3.core.analysis.minMaxProbability(labels, prediction)
Computes the minimum and maximum probabilty of a prediction map given a label map
- Parameters
labels (numpy.ndarray) – labels
prediction (numpy.ndarray) – prediction map with probabilities 0 … 1
- Returns
for each label the minimum and maximum probability
- Return type
numpy.ndarray
- deepd3.core.analysis.reid(labels)
Relabel an existing label map to ensure continuous label ids
- Parameters
labels (numpy.ndarray) – original label map
- Returns
re-computed label map
- Return type
numpy.ndarray
dendrite
- class deepd3.core.dendrite.DendriteSWC(spacing=[1, 1, 1])
- _binarize_swc_w_spheres()
Binarizes SWC file in a given 3D stack with spheres
- convert(target_fn=None)
Convert swc file to tif stack
- Parameters
target_fn (str, optional) – Target path. Defaults to None.
- Returns
save path
- Return type
return
- open(swc_fn, ref_fn)
Open and read the swc and the stack file.
- Parameters
swc_fn (str) – The file path to the swc file
ref_fn (str) – The file path to the stakc file
- deepd3.core.dendrite.line_w_sphere(s, p0, p1, r0, r1, color=1, spacing=[1, 1, 1])
Draw a line with width in 3D space
- Parameters
s (numpy.ndarray) – the 3D stack
p0 (tuple) – point 0 (x, y, z)
p1 (tuple) – point 1 (x, y, z)
r0 (float) – radius for point 0
r1 (float) – radius for point 1
color (int, optional) – Color for drawing, e.g. 255 for np.uint8 stack. Defaults to 1.
spacing (list, optional) – Spacing in 3D (x,y,z). Defaults to [1, 1, 1].
- deepd3.core.dendrite.sphere(s, p0, d, spacing=[1, 1, 1], color=255, debug=False)
Draw a 3D sphere with given diameter d at point p0 in given color.
- Parameters
s (numpy.ndarray) – numpy 3D stack
p0 (tuple) – x, y, z tuple
d (float) – diameter in 1 spacing unit
spacing (list, optional) – x, y, z spacing; x and y spacing must be equal. Defaults to [1, 1, 1].
color (int, optional) – Draw color, e.g. 255 for np.uint8 stack. Defaults to 255.
debug (bool, optional) – if True prints plane related information. Defaults to False.
- deepd3.core.dendrite.xyzr(swc, i)
returns xyz coordinates and radius as tuple from swc pandas DataFrame and loc i, actually it is y, x and z
- Parameters
swc (pandas.DataFrame) – List of traced coordinates
i (int) – current location
- Returns
y, x, z and r coordinates as integers
- Return type
tuple
spines
export
- class deepd3.core.export.ExportCentroids(roi_centroids)
- export(fn)
Exports ROIs to file
- Parameters
fn (str) – target filename and location
- class deepd3.core.export.ExportFolder(rois)
- export(fn, folder)
Export ROIs to folder
- Parameters
fn (str) – file name
folder (str) – target folder
- class deepd3.core.export.ExportImageJ(rois)
- export(fn)
Export ROIs to ImageJ ROI zip file
- Parameters
fn (str) – path to zip file
distance
- deepd3.core.distance._computeDistance(p1, p2, dxy=0.1, dz=0.5)
compute euclidean distance of two points in space. Points are in (Z, Y, X) format
- deepd3.core.distance._countOccurences(arr) dict
Count occurences in array
- Parameters
arr (numpy.ndarray) – Array with non-unique numbers
- Returns
Dictionary with unique numbers as keys and their occurence as value
- Return type
dict
- deepd3.core.distance._distanceMatrix(pt1, pt2, dxy=0.1, dz=0.5) ndarray
Compute distance matrix of points in 3D (Z, Y, X). Works only on 3D data
- Parameters
pt1 (numpy.ndarray) – Points to be matched
pt2 (numpy.ndarray) – Points that can be matched
dxy (float, optional) – Pitch in xy. Defaults to 0.1.
dz (float, optional) – Pitch in z. Defaults to 0.5.
- Returns
distance map from pt1 and pt2 points
- Return type
numpy.ndarray
- deepd3.core.distance.distanceMatrix(pt1, pt2, dxy=0.1, dz=0.5)
Compute distance matrix of points in 2D (Y, X) and 3D (Z, Y, X)
- Parameters
pt1 (numpy.ndarray) – Points to be matched
pt2 (numpy.ndarray) – Points that can be matched
dxy (float, optional) – Pitch in xy. Defaults to 0.1.
dz (float, optional) – Pitch in z. Defaults to 0.5.