kreshuklab / plant-seg

A tool for cell instance aware segmentation in densely packed 3D volumetric images
https://kreshuklab.github.io/plant-seg/
MIT License
89 stars 31 forks source link

Should functionals take PlantSeg classes e.g. `VoxelSize` or `tuple[float, float, float]` #290

Open qin-yu opened 1 month ago

qin-yu commented 1 month ago

I saw the bug here, and started to wonder if we want the functionals/API to take just tuple[float, float, float] or VoxelSize. I wouldn't want to create a VoxelSize first if I know PlantSeg and just want to use the functions.

def _image_postprocessing(image: PlantSegImage, scale_to_origin: bool, export_dtype) -> PlantSegImage:
    if scale_to_origin and image.requires_scaling:
        data = dp.scale_image_to_voxelsize(
            image.get_data(),
            input_voxel_size=image.voxel_size,              # <-- here image.voxel_size is a VoxelSize but input_voxel_size wants tuple
            output_voxel_size=image.original_voxel_size,    # same here
            order=image.interpolation_order(),
        )
        new_voxel_size = image.original_voxel_size

PS: if we decide to let functionals take vallina-typed inputs, then I fix this by adding a .to_tuple() to VoxelSize or rename VoxelSize.voxels_size to VoxelSize.value. So we access image.voxel_size.value or image.voxel_size.to_tuple().

lorenzocerrone commented 3 weeks ago

I think we should write a new functional that also takes the layout as input (like in the current image_rescale_to_voxel_size_task). I agree that the function will only need to know about the tuple.