Skip to content

Fix issue with CZI autostitch options #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
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
87 changes: 46 additions & 41 deletions src/imcflibs/imagej/bioformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,31 @@
return out_file


def get_reader(path_to_file, setFlattenedResolutions=False):
"""Get a Bio-Formats ImageReader for the specified file.

Parameters
----------
path_to_file : str
The full path to the image file.
setFlattenedResolutions : bool, optional
Whether to flatten resolutions in the ImageReader (default: False).

Returns
-------
ImageReader
A configured ImageReader instance for the specified file.
"""
reader = ImageReader()
ome_meta = MetadataTools.createOMEXMLMetadata()
reader.setMetadataStore(ome_meta)
m = DynamicMetadataOptions()
m.setBoolean(ZeissCZIReader.ALLOW_AUTOSTITCHING_KEY, False)
reader.setMetadataOptions(m)
reader.setId(str(path_to_file))
return reader, ome_meta

Check warning on line 377 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L370-L377

Added lines #L370 - L377 were not covered by tests


def get_series_info_from_ome_metadata(path_to_file, skip_labels=False):
"""Get the Bio-Formats series information from a file on disk.

Expand All @@ -378,44 +403,31 @@
>>> count, indices = get_series_info_from_ome_metadata("image.nd2", skip_labels=True)
"""

if not skip_labels:
reader = ImageReader()
reader.setFlattenedResolutions(False)
ome_meta = MetadataTools.createOMEXMLMetadata()
reader.setMetadataStore(ome_meta)
reader.setId(path_to_file)
series_count = reader.getSeriesCount()

reader.close()
reader, ome_meta = get_reader(path_to_file, skip_labels)
series_count = reader.getSeriesCount()
if skip_labels:

Check warning on line 408 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L406-L408

Added lines #L406 - L408 were not covered by tests
# If we are not skipping labels, return the full range
return series_count, range(series_count)

else:
reader = ImageReader()
# reader.setFlattenedResolutions(True)
ome_meta = MetadataTools.createOMEXMLMetadata()
reader.setMetadataStore(ome_meta)
reader.setId(path_to_file)
series_count = reader.getSeriesCount()

series_ids = []
series_names = []
x = 0
y = 0
for i in range(series_count):
reader.setSeries(i)
series_ids = []
series_names = []
x = 0
y = 0
for i in range(series_count):
reader.setSeries(i)

Check warning on line 417 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L412-L417

Added lines #L412 - L417 were not covered by tests

if reader.getSizeX() > x and reader.getSizeY() > y:
name = ome_meta.getImageName(i)
if reader.getSizeX() > x and reader.getSizeY() > y:
name = ome_meta.getImageName(i)

Check warning on line 420 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L419-L420

Added lines #L419 - L420 were not covered by tests

if name not in ["label image", "macro image"]:
series_ids.append(i)
series_names.append(name)
if name not in ["label image", "macro image"]:
series_ids.append(i)
series_names.append(name)

Check warning on line 424 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L422-L424

Added lines #L422 - L424 were not covered by tests

x = reader.getSizeX()
y = reader.getSizeY()
x = reader.getSizeX()
y = reader.getSizeY()

Check warning on line 427 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L426-L427

Added lines #L426 - L427 were not covered by tests

print(series_names)
return len(series_ids), series_ids
print(series_names)
return len(series_ids), series_ids

Check warning on line 430 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L429-L430

Added lines #L429 - L430 were not covered by tests


def write_bf_memoryfile(path_to_file):
Expand Down Expand Up @@ -452,10 +464,7 @@
An instance of `imcflibs.imagej.bioformats.ImageMetadata` containing the extracted metadata.
"""

reader = ImageReader()
ome_meta = MetadataTools.createOMEXMLMetadata()
reader.setMetadataStore(ome_meta)
reader.setId(str(path_to_image))
reader, ome_meta = get_reader(path_to_image)

Check warning on line 467 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L467

Added line #L467 was not covered by tests

metadata = ImageMetadata(
unit_width=ome_meta.getPixelsPhysicalSizeX(0).value(),
Expand Down Expand Up @@ -507,11 +516,7 @@
max_phys_size_z = 0.0

for counter, image in enumerate(filenames):
reader = ImageReader()
reader.setFlattenedResolutions(False)
ome_meta = MetadataTools.createOMEXMLMetadata()
reader.setMetadataStore(ome_meta)
reader.setId(str(image))
reader, ome_meta = get_reader(image)

Check warning on line 519 in src/imcflibs/imagej/bioformats.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/bioformats.py#L519

Added line #L519 was not covered by tests
series_count = reader.getSeriesCount()

# Process only the first image to get values not dependent on series
Expand Down
Loading