napari_dmc_brainmap.preprocessing package
Submodules
napari_dmc_brainmap.preprocessing.preprocessing module
DMC-BrainMap widget for preprocessing of .tif files.
2024 - FJ
- class napari_dmc_brainmap.preprocessing.preprocessing.PreprocessingWidget(parent: QWidget | None = None)[source]
Bases:
QWidgetQWidget for configuring and performing preprocessing operations.
- progress_signal
Signal emitted to update the progress bar with an integer value.
- napari_dmc_brainmap.preprocessing.preprocessing.create_general_widget(widget_type: str, channels: List[str], downsampling_default: int = 3, contrast_limits: Dict[str, str] | None = None) Container[source]
Create a generalized MagicGUI widget for image processing.
- Parameters:
widget_type (str) – The type of widget being created (e.g., ‘RGB’, ‘Single Channel’).
channels (List[str]) – List of available channels to select.
downsampling_default (int) – Default value for the downsampling factor.
contrast_limits (Optional[Dict[str, str]]) – Default contrast limit values for each channel.
- Returns:
The created MagicGUI widget container.
- Return type:
widgets.Container
- napari_dmc_brainmap.preprocessing.preprocessing.do_preprocessing(input_path: Path, channels: List[str], img_list: List[str], preprocessing_params: Dict[str, str | dict], resolution: Tuple[int, int], save_dirs: Dict[str, str]) str[source]
Perform preprocessing on a list of images in a multithreaded manner.
- Parameters:
input_path (Path) – Path to the input directory containing images.
channels (List[str]) – List of channels to process.
img_list (List[str]) – List of image file names to process.
preprocessing_params (Dict[str, Union[str, dict]]) – Parameters for preprocessing operations.
resolution (Tuple[int, int]) – Tuple containing resolution information for preprocessing.
save_dirs (Dict[str, str]) – Dictionary containing paths to save preprocessed images.
- Yields:
int – Progress of the preprocessing operation in percentage.
- Returns:
Animal ID for which preprocessing was performed.
- Return type:
str
napari_dmc_brainmap.preprocessing.preprocessing_tools module
- napari_dmc_brainmap.preprocessing.preprocessing_tools.chunk_list(input_list: List[str], chunk_size: int = 4) List[List[str]][source]
Split a list into smaller chunks of a specified size.
- Parameters:
input_list (List[str]) – The list to be divided into chunks.
chunk_size (int) – The maximum size of each chunk. Default is 4.
- Returns:
A list containing smaller lists (chunks).
- Return type:
List[List[str]]
- napari_dmc_brainmap.preprocessing.preprocessing_tools.create_dirs(params: Dict[str, str | dict], input_path: str | Path) Dict[str, Path][source]
Create directories for saving processed images based on given parameters.
- Parameters:
params (Dict[str, Union[str, dict]]) – Preprocessing parameters including operations and channels.
input_path (Union[str, Path]) – The base path to the input directory.
- Returns:
Dictionary with operation names as keys and created directory paths as values.
- Return type:
Dict[str, Path]
- napari_dmc_brainmap.preprocessing.preprocessing_tools.do_8bit(data: ndarray) ndarray[source]
Convert a 16-bit image to 8-bit format.
- Parameters:
data (np.ndarray) – Input image in 16-bit or 8-bit format.
- Returns:
Converted 8-bit image.
- Return type:
np.ndarray
- Raises:
TypeError – If the input data is neither uint16 nor uint8.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.downsample_and_adjust_contrast(image: ndarray, params: Dict[str, str | list], scale_key: str, contrast_key: str) ndarray[source]
Downsample and adjust contrast of an image.
- Parameters:
image (np.ndarray) – Input image to process.
params (Dict[str, Union[str, list]]) – Parameters for scaling and contrast adjustment.
scale_key (str) – Key to retrieve downsampling factor.
contrast_key (str) – Key to retrieve contrast limits.
- Returns:
Processed image after downsampling and contrast adjustment.
- Return type:
np.ndarray
- napari_dmc_brainmap.preprocessing.preprocessing_tools.get_channels(params: Dict[str, str | dict]) List[str][source]
Extract a unique list of channels from preprocessing parameters.
- Parameters:
params (Dict[str, Union[str, dict]]) – Preprocessing parameters including operations and channels.
- Returns:
List of unique channels to be processed.
- Return type:
List[str]
- napari_dmc_brainmap.preprocessing.preprocessing_tools.load_stitched_images(input_path: str | Path, chan: str, image: str) ndarray | bool[source]
Load a stitched image file from the specified directory.
- Parameters:
input_path (Union[str, Path]) – Path to the directory containing images.
chan (str) – Channel name.
image (str) – Image name (excluding suffix).
- Returns:
Loaded image as a NumPy array, or False if the image is not found.
- Return type:
Union[np.ndarray, bool]
- napari_dmc_brainmap.preprocessing.preprocessing_tools.make_binary(stack_dict: Dict[str, ndarray], params: Dict[str, str | dict], im: str, save_dirs: Dict[str, Path], resolution_tuple: Tuple[int, int]) None[source]
Create binary images for each channel based on a threshold.
- Parameters:
stack_dict (Dict[str, np.ndarray]) – Dictionary containing channel image stacks.
params (Dict[str, Union[str, dict]]) – Parameters for processing.
im (str) – Image name.
save_dirs (Dict[str, Path]) – Directories for saving processed images.
resolution_tuple (Tuple[int, int]) – Desired resolution for the output image.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.make_rgb(stack_dict: Dict[str, ndarray], params: Dict[str, str | dict], im: str, save_dirs: Dict[str, Path], resolution_tuple) None[source]
Create an RGB image from a stack of different channel images.
- Parameters:
stack_dict (Dict[str, np.ndarray]) – Dictionary containing channel image stacks.
params (Dict[str, Union[str, dict]]) – Parameters for processing.
im (str) – Image name.
save_dirs (Dict[str, Path]) – Save directories for processed images.
resolution_tuple – Tuple indicating the resolution.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.make_sharpy_track(stack_dict: Dict[str, ndarray], params: Dict[str, str | dict], im: str, save_dirs: Dict[str, str], resolution_tuple) None[source]
Create Sharpy-track images from a stack of channel images.
Parameters: - stack_dict (Dict[str, np.ndarray]): Dictionary containing channel image stacks. - params (Dict[str, Union[str, dict]]): Parameters for processing. - im (str): Image name. - save_dirs (Dict[str, str]): Save directories for processed images. - resolution_tuple: Tuple indicating the resolution.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.make_single_channel(stack_dict: Dict[str, ndarray], params: Dict[str, str | dict], im: str, save_dirs: Dict[str, Path], resolution_tuple) None[source]
Create single-channel images from a stack of channel images.
- Parameters:
stack_dict (Dict[str, np.ndarray]) – Dictionary containing channel image stacks.
params (Dict[str, Union[str, dict]]) – Parameters for processing.
im (str) – Image name.
save_dirs (Dict[str, Path]) – Save directories for processed images.
resolution_tuple – Tuple indicating the resolution.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.make_stack(stack_dict: Dict[str, ndarray], params: Dict[str, str | dict], im: str, save_dirs: Dict[str, Path], resolution_tuple) None[source]
Create a z-stack of images from a dictionary of channel images.
- Parameters:
stack_dict (Dict[str, np.ndarray]) – Dictionary containing channel image stacks.
params (Dict[str, Union[str, dict]]) – Parameters for processing.
im (str) – Image name.
save_dirs (Dict[str, Path]) – Save directories for processed images.
resolution_tuple – Tuple indicating the resolution.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.preprocess_images(im: str, channels: List[str], input_path, params: Dict[str, str | dict], save_dirs: Dict[str, str], resolution_tuple) None[source]
Preprocess images for a given set of operations and channels.
- Parameters:
im (str) – Image name.
channels (List[str]) – List of channels to process.
input_path (Union[str, Path]) – Path to the input directory containing images.
params (Dict[str, Union[str, dict]]) – Parameters for preprocessing operations.
save_dirs (Dict[str, Path]) – Directories for saving processed images.
resolution_tuple (Tuple[int, int]) – Desired resolution for the output images.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.save_zstack(path: str | Path, stack_dict: Dict[str, ndarray]) None[source]
Save a z-stack of images to a file.
- Parameters:
path (Union[str, Path]) – File path to save the z-stack.
stack_dict (Dict[str, np.ndarray]) – Dictionary of z-stack images.
- napari_dmc_brainmap.preprocessing.preprocessing_tools.select_chans(chan_list: List[str], filter_list: List[str], operation: str) List[str][source]
Select valid channels for a given operation.
- Parameters:
chan_list (List[str]) – List of requested channels.
filter_list (List[str]) – List of available channels.
operation (str) – Name of the operation.
- Returns:
List of selected channels.
- Return type:
List[str]