hybregistration¶
Functions to perform registration between all hybridizations.
- register_final_images(folder, gene=’Nuclei’,
- sub_pic_frac=0.2, use_MPI=False, apply_to_corners=True, apply_warping = True)
– Register stitched images an in all HDF5 file in the folder
- find_reg_final_image(im_file_1, im_file_n,
- max_trans, sub_pic_frac, nr_peaks=8)
– Find the transform that registers image n correctly onto image 1.
- transform_final_image(im_file_n, trans, new_size)
- – Transform an image according to trans.
- transform_data_file(folder, data_name, trans,
- new_size)
– Transform the corners in the pickled data file
- align_sub_region(overlap1, overlap2, nr_peaks)
- – Determine how much overlap2 should be shifted to fit overlap1, help function for find_reg_final_image
-
pysmFISH.stitching_package.hybregistration.
align_sub_region
(overlap1, overlap2, nr_peaks)[source]¶ Determine how much overlap2 should be shifted to fit overlap1.
- overlap1: np.array
- 2D numpy array. Patch of the image that should be compared.
- overlap2: np.array
- 2D numpy array. Patch of the image that should be compared.
- nr_peaks: int
- The number of peaks used to get the best peaks from the phase correlation matrix.
- best_trans: np.array
- Array of len 2 containing ints. Transform that projects overlap2 correctly onto overlap1.
- best_cov: float
- The normalized covariance
-
pysmFISH.stitching_package.hybregistration.
correct_trans_and_size
(trans_relative, old_size_list, max_trans, compare_in_seq)[source]¶ Correct the translations and the size of the registered images.
- trans_relative: np.array
- Array of ints. The array with the non-corrected translation.
- old_size_list: np.array
- Array of ints. The array with the sizes of all the final, non-registered images.
- max_trans: np.array
- Array of ints. Variable to store the largest translation found up to now.
- compare_in_seq: bool
- Determines if we should compare images in sequence or if we should compare all to the first image.
- trans: np.array
- Array of ints. The array with the corrected translations for each image.
- new_size: np.array
- Array of length 2 containing ints. The size the images should have after registration.
-
pysmFISH.stitching_package.hybregistration.
find_reg_final_image
(im_file_1, im_file_n, max_trans, sub_pic_frac, region=None, nr_peaks=8)[source]¶ Find the transform that registers image n correctly onto image 1.
Parameters: im_file_1: pointer
HDF5 group reference or file handle, should contain a dataset “final_image” holding image 1.- im_name_n: pointer
- HDF5 group reference or file handle, should contain a dataset “final_image” holding image n.
- max_trans: np.array
- Array of length 2 with dtype: int. Largest translation currently found.
- sub_pic_frac: float
- The fraction of the size of the original image that should be used to compare images.
- region: list
- List of length four containing ints. The region that should be compared to determine the shift needed for registration. Should be in the order: [y_min, y_max, x_min, x_max]. When region is defined, sub_pic_frac will not be used. By default the code will determine the region itself taking a area around the center of the image with a size determined by sub_pic_frac(Default: None)
- nr_peaks: int
- The number of peaks used to get the best peaks from the phase correlation matrix. (default: 8)
- trans: np.array
- Array of length 2 containing ints. Translation that projects image n correctly onto image 1.
- max_trans: np.array
- Array of shape (1, 2) containing ints. The max_trans value that was passed to this function, replaced by (part of) the current translation if it is larger than max_trans.
- shape_n: tuple
- Tuple of python ints. The shape of image n.
-
pysmFISH.stitching_package.hybregistration.
get_single_relative_trans
(file_name_list, i, gene, max_trans, sub_pic_frac=0.2, region=None, use_MPI=False)[source]¶ Get the translation between image i - 1 and image i.
Get the translation between the image in file_name_list[i - 1] and file_name_list[i].
- file_name_list: list
- List of strings. List of the sf.hdf5-files in the folder.
- i: int
- Index of the second image in the current comparison.
- gene: str
- The gene of which the stitched images are present and should be realigned. Typically this will be ‘Nuclei’, because the smFISH genes will not have enough signal to align the pictures properly. (Default: ‘Nuclei’)
- max_trans: np.array
- Array of ints. Variable to store the largest translation found up to now, initialized at zero.
- sub_pic_frac: float
- The fraction of the size of the original image that should be used to compare images. (Default: 0.2)
- region: list
- List of length four containing ints. The region that should be compared to determine the shift needed for registration. Should be in the order: [y_min, y_max, x_min, x_max]. When region is defined, sub_pic_frac will not be used. By default the code will determine the region itself taking a area around the center of the image with a size determined by sub_pic_frac (Default: None)
- use_MPI: bool
- If True open the files in MPI friendly mode, if False open files in normal single processing mode. (Default: False)
- cur_trans: np.array
- Array of ints. Translation found between the two images that are currently being compared.
- max_trans: np.array
- Array of ints. The largest translation found up to now.
- cur_old_size: np.array
- The sizes of the original final image found in file_name_list at index i.
- i: int
- The index of the second image file used for the current comparison (The first image file is file 1).
-
pysmFISH.stitching_package.hybregistration.
get_single_trans
(file_name_list, i, gene, im_file_1, max_trans, sub_pic_frac=0.2, region=None, use_MPI=False)[source]¶ Get the translation between image 1 and image i.
Get the translation between the image in file 1 and file i from file_name_list.
- file_name_list: list
- List of strings. List of the sf.hdf5-files in the folder.
- i: int
- Index of the current file to compare.
- gene: str
- Gene of which the stitched images are present and should be realigned. Typically this will be ‘Nuclei’, because the smFISH genes will not have enough signal to align the pictures properly. (Default: ‘Nuclei’)
- im_file_1: pointer
- Reference to the group in the first file that contains th final image.
- max_trans: np.array
- Variable to store the largest translation found up to now, initialized at zero.
- sub_pic_frac: float
- The fraction of the size of the original image that should be used to compare images. (Default: 0.2)
- region: list
- List of length four containing ints. The region that should be compared to determine the shift needed for registration. Should be in the order: [y_min, y_max, x_min, x_max]. When region is defined, sub_pic_frac will not be used. By default the code will determine the region itself taking a area around the center of the image with a size determined by sub_pic_frac(Default: None)
- use_MPI: bool
- If True open the files in MPI friendly mode, if False open files in normal single processing mode. (Default: False)
- cur_trans: np.array
- Array of ints. Translation found between the two images that are currently being compared.
- max_trans: np.array
- Array of ints. The largest translation found up to now.
- cur_old_size: np.array
- Array of ints. The sizes of the original final image found in file_name_list at index i.
- i: int
- The index of the second image file used for the current comparison (The first image file is file 1).
-
pysmFISH.stitching_package.hybregistration.
prepare_for_comparing
(folder, gene, compare_in_seq, use_MPI=False)[source]¶ Prepare the file list, first file and init other lists.
- folder: str
- The name of the folder containing the pickled file with stitching data, needs a trailing slash (“/”).
- gene: str
- The gene of which the stitched images are present and should be realigned. Typically this will be ‘Nuclei’, because the smFISH genes will not have enough signal to align the pictures properly. (Default: ‘Nuclei’)
- compare_in_seq: bool
- Determines if we should compare images in sequence or if we should compare all to the first image.
- use_MPI: bool
- If True open the files in MPI friendly mode, if False open files in normal single processing mode. (Default: False)
- file_name_list: list
- List of strings. List of the sf.hdf5-files in the folder.
- trans: np.array
- Array of ints. The array to store the translations, initialized with zeros.
- old_size_list: np.array
- Array of ints. The array to store the sizes of the final images, initialized with zeros.
- max_trans: np.array
- Array of ints. Variable to store the largest translation found up to now, initialized at zero.
Only returned if compare_in_seq is True: file_1: pointer
File handle to the first hdf5 file in the folder.- im_file_1: pointer
- Reference to the group in the first file that contains th final image.
-
pysmFISH.stitching_package.hybregistration.
register_final_images
(folder, gene='Nuclei', sub_pic_frac=0.2, use_MPI=False, apply_to_corners=True, apply_warping=False, region=None, compare_in_seq=False)[source]¶ Register stitched images an in all HDF5 file in the folder
Loops the hybridizations in the HDF5 file, takes the stitched images as indicated by gene and then compares each image to the first image. For the comparison only a small patch of the images is used, the size of this patch can be controlled with “sub_pic_frac”.
- folder: str
- The name of the folder containing the pickled file with stitching data, needs a trailing slash (“/”).
- gene: str
- The gene of which the stitched images are present and should be realigned. Typically this will be ‘Nuclei’, because the smFISH genes will not have enough signal to align the pictures properly. (Default: ‘Nuclei’)
- sub_pic_frac: float
- The fraction of the size of the original image that should be used to compare images. (Default: 0.2)
- use_MPI: bool
- If True open the files in MPI friendly mode, if False open files in normal single processing mode. (Default: False)
- apply_to_corners: bool
- Determines if the found registration will be applied to the tile corners in the pickled stitching data file. (Default: True)
- apply_warping: bool
- Determines if the found registration will be applied as a warp to the final pictures in the hdf5 file, should not be used with large datasets. (Default: False)
- region: list
- List of length four containing ints. The region that should be compared to determine the shift needed for registration. Should be in the order: [y_min, y_max, x_min, x_max]. When region is defined, sub_pic_frac will not be used. By default the code will determine the region itself taking a area around the center of the image with a size determined by sub_pic_frac(Default: None)
- compare_in_seq: bool
- Determines if we should compare images in sequence or if we should compare all to the first image.
-
pysmFISH.stitching_package.hybregistration.
register_final_images_old
(folder, gene='Nuclei', sub_pic_frac=0.2, use_MPI=False, apply_to_corners=True, apply_warping=False, region=None, compare_in_seq=False)[source]¶ Register stitched images an in all HDF5 file in the folder
Loops the hybridizations in the HDF5 file, takes the stitched images as indicated by gene and then compares each image to the first image. For the comparison only a small patch of the images is used, the size of this patch can be controlled with “sub_pic_frac”.
- folder: str
- The name of the folder containing the pickled file with stitching data, needs a trailing slash (“/”).
- gene: str
- The gene of which the stitched images are present and should be realigned. Typically this will be ‘Nuclei’, because the smFISH genes will not have enough signal to align the pictures properly. (Default: ‘Nuclei’)
- sub_pic_frac: float
- The fraction of the size of the original image that should be used to compare images. (Default: 0.2)
- use_MPI: bool
- True open the files in MPI friendly mode, if False open files in normal single processing mode. (Default: False)
- apply_to_corners: bool
- Determines if the found registration will be applied to the tile corners in the pickled stitching data file. (Default: True)
- apply_warping: bool
- Determines if the found registration will be applied as a warp to the final pictures in the hdf5 file, should not be used with large datasets. (Default: False)
- region: list
- List of length four containing ints. The region that should be compared to determine the shift needed for registration. Should be in the order: [y_min, y_max, x_min, x_max]. When region is defined, sub_pic_frac will not be used. By default the code will determine the region itself taking a area around the center of the image with a size determined by sub_pic_frac(Default: None)
- compare_in_seq: bool
- Determines if we should compare images in sequence or if we should compare all to the first image.
-
pysmFISH.stitching_package.hybregistration.
register_final_images_reg_data_only
(folder, gene='Nuclei', sub_pic_frac=0.2, use_MPI=False, apply_to_corners=True, apply_warping=False, region=None, compare_in_seq=False)[source]¶ Register stitched images an in all HDF5 file in the folders. It is modified from register_final_images and saves only the reg_data file with the new coords and nothing in the hdf5 file.
Loops the hybridizations in the HDF5 file, takes the stitched images as indicated by gene and then compares each image to the first image. For the comparison only a small patch of the images is used, the size of this patch can be controlled with “sub_pic_frac”.
- folder: str
- The name of the folder containing the pickled file with stitching data, needs a trailing slash (“/”).
- gene: str
- The gene of which the stitched images are present and should be realigned. Typically this will be ‘Nuclei’, because the smFISH genes will not have enough signal to align the pictures properly. (Default: ‘Nuclei’)
- sub_pic_frac: float
- The fraction of the size of the original image that should be used to compare images. (Default: 0.2)
- use_MPI: bool
- If True open the files in MPI friendly mode, if False open files in normal single processing mode. (Default: False)
- apply_to_corners: bool
- Determines if the found registration will be applied to the tile corners in the pickled stitching data file. (Default: True)
- apply_warping: bool
- Determines if the found registration will be applied as a warp to the final pictures in the hdf5 file, should not be used with large datasets. (Default: False)
- region: list
- List of length four containing ints. The region that should be compared to determine the shift needed for registration. Should be in the order: [y_min, y_max, x_min, x_max]. When region is defined, sub_pic_frac will not be used. By default the code will determine the region itself taking a area around the center of the image with a size determined by sub_pic_frac(Default: None)
- compare_in_seq: bool
- Determines if we should compare images in sequence or if we should compare all to the first image.
-
pysmFISH.stitching_package.hybregistration.
transform_data_file
(folder, data_name, trans, new_size)[source]¶ Transform the corners in the pickled data file
- folder: str
- The name of the folder containing the pickled file with stitching data, needs a trailing slash (“/”).
- data_name: str
- Name of the pickled file with the corner coordinates.
- trans: np.array
- Array of len 2 containing ints. y and x transform of the image.
- new_size: tuple
- Tuple of length 2. The size of the image after the transform.
-
pysmFISH.stitching_package.hybregistration.
transform_final_image
(im_file_n, trans, new_size)[source]¶ Transform an image according to trans.
- im_file_n: pointer
- HDF5 group reference or file handle, should contain a dataset “final_image” holding image n.
- trans: np.array
- Array of len 2 containing ints. y and x transform of the image.
- new_size: tuple
- Tuple of length 2. The size of the image after the transform.