Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pr-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:

permissions:
contents: write
pull-requests: write

steps:
- name: Check out Git repository
Expand Down
30 changes: 19 additions & 11 deletions python/ouroboros/pipeline/backproject_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
mmap = make_tiff_memmap(straightened_volume_path, mode="r")
del mmap
except BaseException as e:
print(f"Direct memory mapping failed (Error {e})\n. Using TiffWriter.")

# Create a new path for the straightened volume
new_straightened_volume_path = join_path(
config.output_file_folder,
Expand Down Expand Up @@ -187,7 +189,8 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
min_bounding_box = chunks_and_boxes[0][
0
] # The first chunk bounding box has the same offset as the minimum bounding box
pipeline_input.backprojection_offset = f"{min_bounding_box.x_min},{min_bounding_box.y_min},{min_bounding_box.z_min}"
pipeline_input.backprojection_offset = \
f"{min_bounding_box.x_min},{min_bounding_box.y_min},{min_bounding_box.z_min}"

# Save the backprojected volume to a series of tif files
offset = (
Expand Down Expand Up @@ -292,7 +295,7 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:

# Copy the intersection volume to the chunk volume
intersection_volume = volume[
x_min : x_max + 1, y_min : y_max + 1, z_min : z_max + 1
x_min: x_max + 1, y_min: y_max + 1, z_min: z_max + 1
]
non_zero_mask = (
np.sum(intersection_volume, axis=-1) != 0
Expand All @@ -301,9 +304,9 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
)

chunk_volume[
int_x_min : int_x_max + 1,
int_y_min : int_y_max + 1,
int_z_min : int_z_max + 1,
int_x_min: int_x_max + 1,
int_y_min: int_y_max + 1,
int_z_min: int_z_max + 1,
][non_zero_mask] = intersection_volume[non_zero_mask]

# If make_backprojection_binary, set all non-zero values to 1
Expand Down Expand Up @@ -342,23 +345,27 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
# Save the backprojected volume to a single tif file
if config.make_single_file:
try:
metadata = {}
# Volume cache resolution is in voxel size, but .tiff XY resolution is in voxels per unit, so we invert.
resolution = [1.0 / voxel_size for voxel_size in volume_cache.get_resolution_um()[:2] * 0.0001]
resolutionunit = "CENTIMETER"
# However, Z Resolution doesn't have an inbuilt property or strong convention, so going with this atm.
metadata = {
"spacing": volume_cache.get_resolution_um()[2],
"unit": "um"
}

if config.backproject_min_bounding_box:
metadata["backprojection_offset_min_xyz"] = (
pipeline_input.backprojection_offset
)

resolution = volume_cache.get_resolution_um()[:2]
resolutionunit = "MICROMETER"

load_and_save_tiff_from_slices(
folder_path,
folder_path + ".tif",
delete_intermediate=False,
compression=config.backprojection_compression,
metadata=metadata,
resolution=resolution,
resolution=resolution, # XY Resolution
resolutionunit=resolutionunit,
)
except BaseException as e:
Expand Down Expand Up @@ -509,7 +516,8 @@ def create_volume_chunks(
# Create bounding boxes along the first axis each containing chunk_size slices
chunks_and_boxes = []

# If backproject_min_bounding_box is True, create a bounding box that contains the minimum bounding box of the volume
# If backproject_min_bounding_box is True,
# create a bounding box that contains the minimum bounding box of the volume.
min_bounding_box = None

# Calculate the range of slices to process
Expand Down
15 changes: 12 additions & 3 deletions python/ouroboros/pipeline/slice_parallel_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ def _process(self, input_data: tuple[any]) -> None | str:
return "No slice rects were provided."

try:
resolution = volume_cache.get_resolution_um()[:2]
resolutionunit = "MICROMETER"
# Volume cache resolution is in voxel size, but .tiff XY resolution is in voxels per unit, so we invert.
resolution = [1.0 / voxel_size for voxel_size in volume_cache.get_resolution_um()[:2] * 0.0001]
resolutionunit = "CENTIMETER"
# However, Z Resolution doesn't have an inbuilt property or strong convention, so going with this.
metadata = {
"spacing": volume_cache.get_resolution_um()[2],
"unit": "um"
}

print(f"Resolution: {volume_cache.get_resolution_um()} | {resolution}")

# Determine the dimensions of the image
has_color_channels = volume_cache.has_color_channels()
Expand All @@ -97,13 +105,14 @@ def _process(self, input_data: tuple[any]) -> None | str:
output_file_path,
temp_data,
software="ouroboros",
resolution=resolution,
resolution=resolution[:2], # XY Resolution
resolutionunit=resolutionunit,
photometric=(
"rgb"
if has_color_channels and num_color_channels > 1
else "minisblack"
),
metadata=metadata,
)
except BaseException as e:
return f"Error creating single tif file: {e}"
Expand Down
Loading