From 9ba335b2781f13088fdbfcee98f99f2e39eca99e Mon Sep 17 00:00:00 2001 From: agerardin Date: Wed, 22 May 2024 12:05:25 -0400 Subject: [PATCH] fix: remove bfio and use tifffile for docker integration. --- .../pyproject.toml | 2 +- .../rt_cetsa_plate_extraction/__init__.py | 27 ++++++++++--------- .../rt_cetsa_plate_extraction/__main__.py | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/segmentation/rt-cetsa-plate-extraction-tool/pyproject.toml b/segmentation/rt-cetsa-plate-extraction-tool/pyproject.toml index 5fca52b76..cb7b1343c 100644 --- a/segmentation/rt-cetsa-plate-extraction-tool/pyproject.toml +++ b/segmentation/rt-cetsa-plate-extraction-tool/pyproject.toml @@ -16,7 +16,7 @@ typer = "^0.7.0" filepattern = "^2.0.5" numpy = "^1.26.4" scikit-image = "0.22.0" -bfio = "^2.3.6" +bfio = "2.3.6" [tool.poetry.group.dev.dependencies] bump2version = "^1.0.1" diff --git a/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__init__.py b/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__init__.py index df6d51bb6..47b457f26 100644 --- a/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__init__.py +++ b/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__init__.py @@ -7,6 +7,7 @@ import bfio import filepattern +import tifffile from polus.images.segmentation.rt_cetsa_plate_extraction.core import PlateParams from polus.images.segmentation.rt_cetsa_plate_extraction.core import create_mask from polus.images.segmentation.rt_cetsa_plate_extraction.core import crop_and_rotate @@ -43,8 +44,8 @@ def extract_plates(inp_dir, pattern, out_dir) -> PlateParams: # extract plate params from first image first_image_path = inp_files[0] - with bfio.BioReader(first_image_path) as reader: - first_image = reader[:] + + first_image = tifffile.imread(first_image_path) params: PlateParams = get_plate_params(first_image) @@ -54,24 +55,24 @@ def extract_plates(inp_dir, pattern, out_dir) -> PlateParams: num_images = len(inp_files) for index, f in enumerate(inp_files): logger.info(f"Processing Image {index+1}/{num_images}: {f}") - with bfio.BioReader(f) as reader: - image = reader[:] - cropped_and_rotated = crop_and_rotate(image, params) + image = tifffile.imread(f) + cropped_and_rotated = crop_and_rotate(image, params) - if index == 1: - first_image = cropped_and_rotated + if index == 1: + first_image = cropped_and_rotated - out_path = out_dir / "images" / (f.stem + POLUS_IMG_EXT) - with bfio.BioWriter(out_path) as writer: - writer.dtype = cropped_and_rotated.dtype - writer.shape = cropped_and_rotated.shape - writer[:] = cropped_and_rotated + out_path = out_dir / "images" / (f.stem + POLUS_IMG_EXT) + with bfio.BioWriter(out_path) as writer: + writer.dtype = cropped_and_rotated.dtype + writer.shape = cropped_and_rotated.shape + writer[:] = cropped_and_rotated # save plate parameters for the first processed image processed_params = get_plate_params(first_image) - plate_path = out_dir / "params" / "plate.csv" + plate_path = out_dir / "params" / "plate.json" with plate_path.open("w") as f: f.write(processed_params.model_dump_json()) # type: ignore + logger.info(f"Plate params saved: {plate_path}") # save the corresponding mask for reference mask = create_mask(processed_params) diff --git a/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__main__.py b/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__main__.py index f70c663c1..8bfc5513b 100644 --- a/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__main__.py +++ b/segmentation/rt-cetsa-plate-extraction-tool/src/polus/images/segmentation/rt_cetsa_plate_extraction/__main__.py @@ -75,7 +75,7 @@ def main( "masks": [ (Path("masks") / f"{inp_files[0].stem}{POLUS_IMG_EXT}").as_posix(), ], - "params": [Path("params") / "plate.csv"], + "params": [Path("params") / "plate.json"], } with (out_dir / "preview.json").open("w") as f: