At the moment we are using a simple scale factor, but it would be better to scale the images to the same pixel size before registration. We can easily get both the Xenium and MACSima pixel sizes from their metadata and we can convert the scale_factor parameter to a desired pixel size for registration. The current approximate setup seems to work OK, but could be improved. See:
|
def preprocess_reg(img, scale_factor): |
|
""" |
|
Prepares an image for use with cv SIFT feature detection. |
|
|
|
Parameters: |
|
----------- |
|
img : dask.array or numpy.ndarray |
|
Input image to preprocess |
|
scale_factor : int |
|
Downscaling factor for the image |
|
|
|
Returns: |
|
-------- |
|
numpy.ndarray |
|
Preprocessed image ready for SIFT feature detection |
|
""" |
|
matrix = np.array([[scale_factor, 0, 0], [0, scale_factor, 0], [0, 0, 1]]) |
|
output_shape = np.asarray(img.shape) |
|
output_shape = (output_shape / scale_factor).astype("uint16") |
|
|
|
img = dask_image.ndinterp.affine_transform( |
|
img, |
|
matrix=matrix, |
|
output_shape=output_shape, |
|
) |
|
img = skimage.exposure.equalize_adapthist(img) |
|
img = (img - np.min(img)) / (np.max(img) - np.min(img)) * 255 |
|
img = img.astype("uint8") |
|
parser.add_argument("scale_factor", help="Scale Factor for downsampling") |
At the moment we are using a simple scale factor, but it would be better to scale the images to the same pixel size before registration. We can easily get both the Xenium and MACSima pixel sizes from their metadata and we can convert the
scale_factorparameter to a desired pixel size for registration. The current approximate setup seems to work OK, but could be improved. See:MACSimaXenium/src/xenium_macsima_core_registration/xenium_macsima_core_registration.py
Lines 471 to 498 in 5692d3c
MACSimaXenium/src/xenium_macsima_core_registration/xenium_macsima_core_registration.py
Line 588 in 5692d3c