arjunrajlaboratory / DeepTile

Large image tiling and stitching library for scaling Python functions to arbitrary input image sizes.
MIT License
11 stars 0 forks source link

DeepTile does not arrange tiles correctly on an nd2 file #3

Open Eddymorphling opened 1 week ago

Eddymorphling commented 1 week ago

Hi folks, I am trying to use deep to perform 2D stitching on a multi-position nd2 file acquired on our spinning disc. Below is what is use to run DeepTilebut I noticed that the FOVs are not in the correct position in the stitched dataset. Let me also mention that my raw multi-position .nd2 file is not a regular shape. How does DeepTileread stage positions from the .nd2 file. Here is my script that i currently use.

import numpy as np
import tifffile
from deeptile import load
from deeptile.extensions import stitch
from pathlib import Path
import zarr
from skimage.transform import pyramid_gaussian

# Define the input file path
image_path = '/Processed/33975/33975-far label.nd2'
image = Path(image_path)

# Load the image and get tiles
dt = load(str(image))
tiles = dt.get_tiles()  

# Stitch the image with blending
stitched = stitch.stitch_image(tiles, blend=True, sigma=10)

# Create a multi-resolution pyramid
pyramid = tuple(pyramid_gaussian(stitched, max_layer=4, downscale=2, multichannel=True))

# Define the output file path for the pyramid
output_path_pyramid = image.parent / (image.stem + '_stitched_pyramid.zarr')

# Save the pyramid as a Zarr file with zlib compression
zarr_group = zarr.open_group(str(output_path_pyramid), mode='w')
compressor = zarr.Zlib(level=3)  # Set the compression level 
for i, level in enumerate(pyramid):
    zarr_group.create_dataset(f'level_{i}', data=level, chunks=True, compressor=compressor)

print(f"Multi-resolution pyramid saved to {output_path_pyramid}")
zjniu commented 3 days ago

@Eddymorphling Do your .nd2 files have tiles that have a consistent overlap with each other? If possible, it would be helpful to provide a sample file so I could debug further!