megafish.register module
- shift_cycle_cYXyx(zarr_path, group, sift_kwargs=None, match_kwargs=None, ransac_kwargs=None, subfooter='', footer='_shift_cycle')[source]
Calculates and stores cycle shifts for aligning image tiles based on phase correlation and feature matching. If the SIFT detector parameters are not provided, only phase correlation is used to calculate shifts.
- Parameters:
zarr_path (str) – Path to the Zarr file containing image data.
group (str) – Group name in the Zarr file where image data is stored.
sift_kwargs (dict, optional) – Parameters for the SIFT detector; defaults to None.
match_kwargs (dict, optional) – Parameters for matching descriptors; defaults to None.
ransac_kwargs (dict, optional) – Parameters for RANSAC transformation; defaults to None.
subfooter (str, optional) – String to append before the footer in the output CSV filename; defaults to an empty string.
footer (str, optional) – String appended to the output CSV filename; defaults to “_shift_cycle”.
- Returns:
The function saves shift information as a CSV file.
- Return type:
None
- shift_tile_cYXyx(zarr_path, group_mov, group_stitched, max_shift=100, sift_kwargs=None, match_kwargs=None, ransac_kwargs=None, subfooter='', footer='_shift_tile')[source]
Calculates and stores tile shifts for aligning image tiles based on phase correlation and feature matching. If the SIFT detector parameters are not provided, only phase correlation is used to calculate shifts.
- Parameters:
zarr_path (str) – Path to the Zarr file containing image data.
group_mov (str) – Group name in the Zarr file for the moving image data.
group_stitched (str) – Group name in the Zarr file for the reference stitched image data.
max_shift (int, optional) – Maximum allowed shift (in pixels); defaults to 100.
sift_kwargs (dict, optional) – Parameters for the SIFT detector; defaults to None.
match_kwargs (dict, optional) – Parameters for matching descriptors; defaults to None.
ransac_kwargs (dict, optional) – Parameters for RANSAC transformation; defaults to None.
subfooter (str, optional) – String to append before the footer in the output CSV filename; defaults to an empty string.
footer (str, optional) – String appended to the output CSV filename; defaults to “_shift_tile”.
- Returns:
The function saves the shift matrix as a CSV file without returning any value.
- Return type:
None
- dummy_shift_tile(zarr_path, shift_cycle_footer, subfooter='', footer='_shift_tile')[source]
Creates a dummy tile shifts CSV file with identity transformation values.
- Parameters:
zarr_path (str) – Path to the Zarr file associated with the image data.
shift_cycle_footer (str) – Footer of the shift cycle CSV file to read and modify.
subfooter (str, optional) – String to append before the footer in the output CSV filename; defaults to an empty string.
footer (str, optional) – String appended to the output CSV filename; defaults to “_shift_tile”.
- Returns:
The function saves a dummy shifts CSV file.
- Return type:
None
- merge_shift_cYXyx(zarr_path, group, subfooter='', cycle_footer='_shift_cycle', tile_footer='_shift_tile', footer='_shift_tile_cycle')[source]
Merges cycle and tile shift transformations and saves the combined shifts as a CSV file.
- Parameters:
zarr_path (str) – Path to the Zarr file associated with the image data.
group (str) – Group name in the Zarr file where image data is stored.
subfooter (str, optional) – String to append before the footer in the output CSV filename; defaults to an empty string.
cycle_footer (str, optional) – Footer of the cycle shift CSV file; defaults to “_shift_cycle”.
tile_footer (str, optional) – Footer of the tile shift CSV file; defaults to “_shift_tile”.
footer (str, optional) – String appended to the output CSV filename; defaults to “_shift_tile_cycle”.
- Returns:
The function saves the merged shifts as a CSV file.
- Return type:
None
- get_edges(n_cycle, n_tile_y, n_tile_x, df_shift, n_y_stitched, n_x_stitched, n_y, n_x, margin=500)[source]
Calculates the edges of tiles after applying transformations, taking into account tile positions and transformations.
- Parameters:
n_cycle (int) – Number of cycles.
n_tile_y (int) – Number of tiles along the y-axis.
n_tile_x (int) – Number of tiles along the x-axis.
df_shift (pandas.DataFrame) – DataFrame containing shift transformation matrices for each cycle and tile.
n_y_stitched (int) – Height of each stitched tile.
n_x_stitched (int) – Width of each stitched tile.
n_y (int) – Height of each individual tile.
n_x (int) – Width of each individual tile.
margin (int, optional) – Margin added to the edges for buffer space; defaults to 500.
- Returns:
A DataFrame containing the min and max x and y coordinates of each tile after transformation, including the cycle, tile_y, and tile_x.
- Return type:
- create_chunk_dataframe(shape, chunk_size)[source]
Creates a DataFrame representing the coordinates of chunks within a grid based on the specified shape and chunk size.
- Parameters:
- Returns:
- A DataFrame containing the chunk indices and coordinates, with columns:
’chunk_y’, ‘chunk_x’, ‘upper_y’, ‘lower_y’, ‘left_x’, ‘right_x’.
- Return type:
- get_overlap(chunk_sel, tiles_df, cycle)[source]
Finds the overlapping tiles within a specified chunk for a given cycle.
- Parameters:
chunk_sel (dict) – A dictionary containing the coordinates of the chunk with keys: ‘left_x’, ‘right_x’, ‘upper_y’, ‘lower_y’.
tiles_df (pandas.DataFrame) – A DataFrame containing tile information with columns: ‘cycle’, ‘min_x’, ‘max_x’, ‘min_y’, ‘max_y’.
cycle (int) – The cycle number for which to find overlapping tiles.
- Returns:
A DataFrame of tiles that overlap with the specified chunk in the given cycle.
- Return type:
- registration_cYXyx(zarr_path, group_tile, group_ref, chunk_size, subfooter='', shift_footer='_shift_tile_cycle', footer='_reg')[source]
Registers and stitches image tiles based on transformation matrices, creating a registered dataset in Zarr format.
- Parameters:
zarr_path (str) – Path to the Zarr file containing the image data.
group_tile (str) – Group name in the Zarr file for the tiles to be registered.
group_ref (str) – Group name in the Zarr file for the reference stitched images.
chunk_size (tuple of int) – Size of each chunk (chunk_height, chunk_width).
subfooter (str, optional) – String to append before the shift footer in the output filename; defaults to an empty string.
shift_footer (str, optional) – Footer of the shift CSV file; defaults to “_shift_tile_cycle”.
footer (str, optional) – String appended to the output Zarr group name; defaults to “_reg”.
- Returns:
The function saves the registered and stitched images to a new Zarr group.
- Return type:
None
- registration_cYXyx_noref(zarr_path, group_tile, stitched_shape, chunk_size, subfooter='', shift_footer='_shift_tile_cycle', footer='_reg')[source]
Registers and stitches image tiles based on transformation matrices, creating a registered dataset in Zarr format. This version does not use a reference stitched image group, but instead takes the stitched shape directly as input.
- Differences from registration_cYXyx:
This function does not rely on a reference stitched image group (group_ref).
The stitched shape (stitched_shape) is provided directly as an argument, specifying the dimensions of the stitched images (number of tiles in y and x directions and the dimensions of each tile).
- Parameters:
zarr_path (str) – Path to the Zarr file containing the image data.
group_tile (str) – Group name in the Zarr file for the tiles to be registered.
stitched_shape (tuple of int) – Shape of the stitched image (n_tile_stitched_y, n_tile_stitched_x, n_y_stitched, n_x_stitched).
chunk_size (tuple of int) – Size of each chunk (chunk_height, chunk_width).
subfooter (str, optional) – String to append before the shift footer in the output filename; defaults to an empty string.
shift_footer (str, optional) – Footer of the shift CSV file; defaults to “_shift_tile_cycle”.
footer (str, optional) – String appended to the output Zarr group name; defaults to “_reg”.
- Returns:
The function saves the registered and stitched images to a new Zarr group.
- Return type:
None