napari_dmc_brainmap.segment.processing package

Submodules

napari_dmc_brainmap.segment.processing.atlas_utils module

napari_dmc_brainmap.segment.processing.atlas_utils.angleSlice(x_angle: float, y_angle: float, z: float, annot_bool: ndarray, z_idx: int, z_res: float, bregma: List[int | float], xyz_dict: Dict[str, Tuple[float, int]]) ndarray[source]

Generate a slice of the brain annotation volume at a specific angle and z-coordinate.

Parameters:
  • x_angle (float) – Angle along the x-axis in degrees.

  • y_angle (float) – Angle along the y-axis in degrees.

  • z (float) – Z-coordinate for the slice in mm.

  • annot_bool (np.ndarray) – Binary annotation volume.

  • z_idx (int) – Index of the z-coordinate.

  • z_res (float) – Resolution along the z-axis in mm.

  • bregma (List[Union[int, float]]) – Dictionary containing bregma coordinates.

  • xyz_dict (Dict[str, Tuple[float, int]]) – Dictionary with axis resolutions

  • (e.g. (and dimensions) – (res, dim), ‘y’: (res, dim), ‘z’: (res, dim)}).

  • {'x' – (res, dim), ‘y’: (res, dim), ‘z’: (res, dim)}).

Returns:

A 2D slice of the annotation volume at the specified angle and z-coordinate.

Return type:

np.ndarray

napari_dmc_brainmap.segment.processing.atlas_utils.calculateImageGrid(x_res: int, y_res: int) Tuple[ndarray, ndarray, ndarray][source]

Calculate a 2D image grid based on x and y resolutions.

Parameters:
  • x_res (int) – The resolution along the x-axis.

  • y_res (int) – The resolution along the y-axis.

Returns:

A tuple containing the grid, raveled x-coordinates, and raveled y-coordinates.

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

napari_dmc_brainmap.segment.processing.atlas_utils.loadAnnotBool(atlas: str) ndarray[source]

Load or create a binary annotation volume for a given atlas.

Parameters:

atlas (str) – The name of the atlas.

Returns:

A binary annotation volume where 0 indicates outside the brain and 255 indicates inside the brain.

Return type:

np.ndarray

napari_dmc_brainmap.segment.processing.centroid_finder module

class napari_dmc_brainmap.segment.processing.centroid_finder.CentroidFinder(input_path: Path, mask_folder: str, output_folder: str, channels: List[str], mask_type: str = 'cells')[source]

Bases: object

Class for finding centroids in segmentation mask images and saving them as CSV files.

find_centroids_for_image(mask_image_path: Path, save_path: Path) None[source]

Find centroids for a given mask image and save results as a CSV.

Parameters:
  • mask_image_path (Path) – Path to the mask image file.

  • save_path (Path) – Path to save the centroid CSV file.

process_all_masks(progress_callback: None | callable = None) None[source]

Iterate over all mask images in the specified folder and process them to find centroids.

Parameters:

progress_callback (Union[None, callable], optional) – Callback function for updating progress. Defaults to None.

process_all_masks_parallel(max_workers: int = 4, progress_callback: None | callable = None) None[source]

Parallel processing of mask images using multiple CPU cores.

Parameters:
  • max_workers (int, optional) – Maximum number of parallel workers. Defaults to 4.

  • progress_callback (Union[None, callable], optional) – Callback function for updating progress. Defaults to None.

napari_dmc_brainmap.segment.processing.presegmentation_tools module

class napari_dmc_brainmap.segment.processing.presegmentation_tools.CellsSegmenter(input_path: Path, general_params: dict, cells_params: dict, preseg_params: dict)[source]

Bases: PreSegmenter

Class for performing cell segmentation tasks including preprocessing, segmentation, and centroid detection.

find_centroids(segmented_image: ndarray) ndarray[source]

Find centroids in the segmented image.

Parameters:

segmented_image (np.ndarray) – Segmentation mask.

Returns:

Centroid coordinates.

Return type:

np.ndarray

load_image(image_path: Path, chan: str) ndarray[source]

Load an image for segmentation.

Parameters:
  • image_path (Path) – Path to the image file.

  • chan (str) – Channel identifier.

Returns:

Loaded image as a NumPy array.

Return type:

np.ndarray

preprocess_image(image: ndarray) ndarray[source]

Preprocess the image for segmentation.

Parameters:

image (np.ndarray) – Input image.

Returns:

Preprocessed image.

Return type:

np.ndarray

process_images(progress_callback: None | callable = None) None[source]

Process all images for segmentation.

Parameters:

progress_callback (Union[None, callable]) – Callback function for progress updates.

process_images_parallel(max_workers: int = 4, progress_callback: None | callable = None) None[source]

Process images in parallel.

Parameters:
  • max_workers (int) – Number of parallel workers.

  • progress_callback (Union[None, callable]) – Callback function for progress updates.

save_mask_image(segmentation: ndarray, mask_save_fn: Path) None[source]

Save the segmentation mask as a TIFF image.

Parameters:
  • segmentation (np.ndarray) – Segmentation mask.

  • mask_save_fn (Path) – File path to save the mask.

segment_cells(image_path: Path, save_path: Path, mask_save_fn: Path, chan: str, seg_im_suffix: str) None[source]

Perform segmentation on a single image and save the results.

Parameters:
  • image_path (Path) – Path to the image file.

  • save_path (Path) – Path to save segmentation results.

  • mask_save_fn (Path) – Path to save segmentation mask.

  • chan (str) – Channel identifier.

  • seg_im_suffix (str) – Image suffix.

segment_image(image: ndarray) ndarray[source]

Perform segmentation on the preprocessed image.

Parameters:

image (np.ndarray) – Preprocessed image.

Returns:

Segmentation mask.

Return type:

np.ndarray

class napari_dmc_brainmap.segment.processing.presegmentation_tools.PreSegmenter(input_path: Path, general_params: dict)[source]

Bases: object

Base class for pre-segmentation tasks including loading data, preparing directories, and excluding objects based on registration data.

exclude_segment_objects(im: str, segmented_image: ndarray, seg_idx: ndarray, seg_im_suffix: str) ndarray[source]

Exclude objects from the segmentation based on atlas registration.

Parameters:
  • im (str) – Image name.

  • segmented_image (np.ndarray) – Binary segmentation mask.

  • seg_idx (np.ndarray) – Array of segment indices.

  • seg_im_suffix (str) – Suffix of the segmented image.

Returns:

Updated segment indices after exclusion.

Return type:

np.ndarray

get_drop_mask(regi_index: int, x_im: ndarray, y_im: ndarray) ndarray[source]

Get a mask for excluding objects based on atlas registration.

Parameters:
  • regi_index (int) – Registration index.

  • x_im (np.ndarray) – X-coordinates of image objects.

  • y_im (np.ndarray) – Y-coordinates of image objects.

Returns:

Boolean mask for excluding objects.

Return type:

np.ndarray

get_regi_index(im: str, seg_im_suffix: str) int[source]

Get the registration index corresponding to the given image.

Parameters:
  • im (str) – Image name.

  • seg_im_suffix (str) – Suffix of the segmented image.

Returns:

Registration index.

Return type:

int

load_image_list(chan: str, im_class: str) Tuple[Path, List[str], str][source]

Load the list of images to be segmented.

Parameters:
  • chan (str) – Channel identifier.

  • im_class (str) – Class of the image (e.g., ‘rgb’, ‘single_channel’).

Returns:

Directory path, list of images, and image suffix.

Return type:

Tuple[Path, List[str], str]

load_registration_data() None[source]

Load registration data including transformation matrices and atlas information.

prepare_segmentation_folders(seg_folder: str, chan: str) Tuple[Path, Path] | Path[source]

Prepare directories for segmentation tasks.

Parameters:
  • seg_folder (str) – Folder name for segmentation masks.

  • chan (str) – Channel identifier.

Returns:

Paths to prepared directories.

Return type:

Union[Tuple[Path, Path], Path]

save_to_csv(data: DataFrame, file_path: Path) None[source]

Save data to a CSV file.

Parameters:
  • data (pd.DataFrame) – Data to save.

  • file_path (Path) – Path to save the CSV file.

class napari_dmc_brainmap.segment.processing.presegmentation_tools.ProjectionSegmenter(input_path: Path, general_params: dict, projection_params: dict | None = None)[source]

Bases: PreSegmenter

Class for performing projection segmentation tasks.

process_images(progress_callback: None | callable = None) None[source]

Process all projection images for segmentation.

Parameters:

progress_callback (Union[None, callable]) – Callback function for progress updates.

process_images_parallel(max_workers=4, progress_callback: None | callable = None) None[source]

Process projection images in parallel using multiple CPU cores.

Parameters:
  • max_workers (int) – Number of worker processes to run in parallel.

  • progress_callback (Union[None, callable]) – Callback function to report progress.

segment_projection(image_path: Path, save_path: Path, binary_suffix: str) None[source]

Perform segmentation on a single projection image and save the results.

Parameters:
  • image_path (Path) – Path to the image file.

  • save_path (Path) – Path to save segmentation results.

  • binary_suffix (str) – Suffix of the binary image.

Module contents