Skip to content

Commit

Permalink
fix: remove bfio and use tifffile for docker integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
agerardin committed May 22, 2024
1 parent bf32f5c commit 9ba335b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion segmentation/rt-cetsa-plate-extraction-tool/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9ba335b

Please sign in to comment.