magmap.cv.stack_detect module¶
Stack blob detector.
Detect blobs within a stack that has been chunked to allow parallel processing.
- class magmap.cv.stack_detect.Blocks(sub_roi_slices: ndarray, sub_rois_offsets: ndarray, denoise_max_shape: ndarray, exclude_border: Sequence[int], tol: ndarray, overlap_base: ndarray, overlap: ndarray, overlap_padding: ndarray, max_pixels: ndarray)[source]¶
Bases:
NamedTupleBlock processing chunk tuples.
- class magmap.cv.stack_detect.StackDetector[source]¶
Bases:
objectDetect blobs within a stack in a way that allows multiprocessing without global variables.
- Variables:
img (
np.ndarray) – Full image array.last_coord (
np.ndarray) – Indices of last sub-ROI given as coordinates in z,y,x.denoise_max_shape (Tuple[int]) – Maximum shape of each unit within each sub-ROI for denoising.
exclude_border (bool) – Sequence of border pixels in x,y,z to exclude; defaults to None.
coloc (bool) – True to perform blob co-localizations; defaults to False.
channel (Sequence[int]) – Sequence of channels; defaults to None to detect in all channels.
- channel = None¶
- coloc = False¶
- denoise_max_shape = None¶
- classmethod detect_blobs_sub_rois(img, sub_roi_slices, sub_rois_offsets, denoise_max_shape, exclude_border, coloc, channel)[source]¶
Process blobs in chunked sub-ROIs via multiprocessing.
- Parameters:
img (
np.ndarray) – Array in which to detect blobs.sub_roi_slices (
np.ndarray) – Numpy object array containing chunked sub-ROIs within a stack.sub_rois_offsets (
np.ndarray) – Numpy object array of the same shape assub_roiswith offsets in z,y,x corresponding to each sub-ROI. Offets are used to transpose blobs into absolute coordinates.denoise_max_shape (Tuple[int]) – Maximum shape of each unit within each sub-ROI for denoising.
exclude_border (Tuple[int]) – Sequence of border pixels in x,y,z to exclude; defaults to None.
coloc (bool) – True to perform blob co-localizations; defaults to False.
channel (Sequence[int]) – Sequence of channels, where None detects in all channels.
- Returns:
Numpy object array of blobs corresponding to
sub_rois, with each set of blobs given as a Numpy array in the format,[n, [z, row, column, radius, ...]], including additional elements as given in :meth:StackDetect.detect_sub_roi.- Return type:
np.ndarray
- classmethod detect_sub_roi(coord, offset, last_coord, denoise_max_shape, exclude_border, sub_roi, channel, img_path=None, coloc=False)[source]¶
Perform 3D blob detection within a sub-ROI without accessing class attributes, such as for spawned multiprocessing.
- Parameters:
coord (
Sequence[int]) – Coordinate of the sub-ROI in the order z,y,x.offset (
Sequence[int]) – Offset of the sub-ROI within the full ROI, in z,y,x.exclude_border (
bool) – See attributes.sub_roi (
ndarray) – Array in which to perform detections.img_path (
Optional[str], default:None) – Path from which to load metadatat; defaults to None. If given, the command line arguments will be reloaded to set up the image and processing parameters.coloc (
bool, default:False) – True to perform blob co-localizations; defaults to False.channel (
Sequence[int]) – Sequence of channels, where None detects in all channels.
- Returns:
coord: the coordinate given back again to identify the sub-ROI positionblobs: array of detected blobs
- Return type:
Tuple of
- classmethod detect_sub_roi_from_data(coord, sub_roi_slices, offset)[source]¶
Perform 3D blob detection within a sub-ROI using data stored as class attributes for forked multiprocessing.
- Parameters:
- Returns:
The coordinate given back again to identify the sub-ROI position and an array of detected blobs.
- Return type:
Tuple[int],
np.ndarray
- exclude_border = None¶
- img = None¶
- last_coord = None¶
- class magmap.cv.stack_detect.StackPruner[source]¶
Bases:
objectPrune blobs within a stack in a way that allows multiprocessing without global variables.
- Variables:
blobs_to_prune – List of tuples to be passed to :meth:
detector.remove_close_blobs. The final colums should have the coordinates of the sub-ROI inz, y, xorder as given bychunking.merge_blobs().
- blobs_to_prune = None¶
- classmethod prune_blobs_mp(img, seg_rois, overlap, tol, sub_roi_slices, sub_rois_offsets, channels, overlap_padding=None)[source]¶
Prune close blobs within overlapping regions by checking within entire planes across the ROI in parallel with multiprocessing.
- Parameters:
img (
np.ndarray) – Array in which to detect blobs.seg_rois (
np.ndarray) – Blobs from each sub-region.overlap – 1D array of size 3 with the number of overlapping pixels for each image axis.
tol – Tolerance as (z, y, x), within which a segment will be considered a duplicate of a segment in the master array and removed.
sub_roi_slices (
np.ndarray) – Object array of ub-regions, used to check size.sub_rois_offsets – Offsets of each sub-region.
channels (Sequence[int]) – Sequence of channels; defaults to None to detect in all channels.
overlap_padding (default:
None) – Sequence of z,y,x for additional padding beyondoverlap. Defaults to None to usetolas padding.
- Returns:
All blobs as a Numpy array and a data frame of pruning stats, or None for both if no blobs are in the
seg_rois.- Return type:
np.ndarray,pd.DataFrame
- classmethod prune_overlap(i, pruner)[source]¶
Prune overlapping blobs.
- Parameters:
i (int) – Index of :attr:
blobs_to_prune.pruner – Corresponding value from :attr:
blobs_to_prune.
- Returns:
Blobs after pruning and pruning ratio metrics.
- Return type:
np.ndarray, tuple
- classmethod prune_overlap_by_index(i)[source]¶
Prune an overlapping region.
- Parameters:
i (int) – Index in :attr:
blobs_to_prune.- Returns:
The results from
prune_overlap().
- class magmap.cv.stack_detect.StackTimes(value)[source]¶
Bases:
EnumStack processing durations.
- DETECTION = 'Detection'¶
- PRUNING = 'Pruning'¶
- TOTAL = 'Total_stack'¶
- magmap.cv.stack_detect.detect_blobs_blocks(filename_base, image5d, offset=None, size=None, channels=None, verify=False, save_dfs=True, full_roi=False, coloc=False)[source]¶
Detect blobs by block processing of a large image.
All channels are processed in the same blocks.
- Parameters:
filename_base (
str) – Base path to use file output.image5d (
ndarray) – Large image to process as a Numpy array of t,z,y,x,[c]offset (
Optional[Sequence[int]], default:None) – Sub-image offset given as coordinates in z,y,x.size (
Optional[Sequence[int]], default:None) – Sub-image shape given in z,y,x.channels (
Optional[Sequence[int]], default:None) – Sequence of channels, where None detects in all channels.verify (
bool, default:False) – True to verify detections against truth database; defaults to False.save_dfs (
bool, default:True) – True to save data frames to file; defaults to True.full_roi (
bool, default:False) – True to treatimage5das the full ROI; defaults to False.coloc (
bool, default:False) – True to perform blob co-localizations; defaults to False.
- Returns:
stats_detection: accuracy metrics frommagmap.cv.detector.verify_roisfdbk: feedback message from this same functionblobs: detected blobs
- Return type:
Tuple of
- magmap.cv.stack_detect.detect_blobs_stack(filename_base, subimg_offset=None, subimg_size=None, coloc=False)[source]¶
Detect blobs in a full stack, such as a whole large image.
Process channels in separate sets of blocks if their profiles specify different block sizes.
- Parameters:
filename_base (
str) – Base image filename, for saving files.subimg_offset (
Optional[Sequence[int]], default:None) – Sub-image offset asz,y,xto load fromconfig.image5d; defaults to None.subimg_size (
Optional[Sequence[int]], default:None) – Sub-image size asz,y,xto load fromconfig.image5d; defaults to None.coloc (
bool, default:False) – True to also detect blob-colocalizations based on image intensity; defaults to False. For match-based colocalizations, use thecoloc_matchtask (magmap.colocalizer.StackColocalizer.colocalize_stack()) instead.
- Returns:
stats_detection: combined accuracy metrics frommagmap.cv.detector.verify_roisfdbk: feedback message from this same functionblobs: detected blobs across all channels inmagmap.settings.config.channel
- Return type:
Tuple of
- magmap.cv.stack_detect.setup_blocks(settings, shape)[source]¶
Set up blocks for block processing
Each block is a chunk of a larger image processed sequentially or in parallel to optimize resource usage.
- Parameters:
settings (
SettingsDict) – Settings dictionary that defines that the blocks.
- Return type:
- Returns:
A named tuple of the block parameters.