Skip to content

Commit

Permalink
Automatically convert sequences of slices into a single volume for ba…
Browse files Browse the repository at this point in the history
…ckprojection.
  • Loading branch information
We-Gold committed Aug 5, 2024
1 parent da3b97d commit 956569f
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions python/ouroboros/pipeline/backproject_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from ouroboros.helpers.bounding_boxes import BoundingBox
from .pipeline import PipelineStep
from ouroboros.helpers.options import BackprojectOptions
from ouroboros.helpers.files import join_path, load_and_save_tiff_from_slices
from ouroboros.helpers.files import (
get_sorted_tif_files,
join_path,
load_and_save_tiff_from_slices,
)

import concurrent.futures
import tifffile
Expand Down Expand Up @@ -75,15 +79,25 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
)

# Save the straightened volume to a new tif file
with tifffile.TiffWriter(
new_straightened_volume_path
) as tif, tifffile.TiffFile(straightened_volume_path) as tif_in:
for i in range(len(tif_in.pages)):
tif.save(
tif_in.pages[i].asarray(),
contiguous=True,
compression=None,
)
with tifffile.TiffWriter(new_straightened_volume_path) as tif:
if straightened_volume_path.endswith(".tif"):
# Read the single tif file
with tifffile.TiffFile(straightened_volume_path) as tif_in:
for i in range(len(tif_in.pages)):
tif.save(
tif_in.pages[i].asarray(),
contiguous=True,
compression=None,
)
else:
# Read the tif files from the folder
images = get_sorted_tif_files(straightened_volume_path)
for image in images:
tif.save(
tifffile.imread(join_path(straightened_volume_path, image)),
contiguous=True,
compression=None,
)

straightened_volume_path = new_straightened_volume_path

Expand Down

0 comments on commit 956569f

Please sign in to comment.