Skip to content
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

And endpoint to retrieve associated images and thumbnails #149

Merged
merged 13 commits into from
Sep 13, 2023

Conversation

naglepuff
Copy link
Collaborator

Fix #138

Caveats:

  1. Has a limited way to look for associated images. It checks ImageDescription, which can find label and macro images for svs files, but not always. It falls back to NewSubfileType, which can find macro images
  2. Doesn't try very hard to extract a thumbnail. If the tiled images are compressed with a method other than JPEG, it doesn't work

UI integration is for demonstration/testing, and will likely not make it through the review process for this PR, as a UI overhaul is in progress, and the new endpoint can be integrated in to that as part of a separate PR.

Comment on lines 37 to 44
<div class="inline-flex">
<img src="{{ image_url(child_image.name, 'label') }}" alt="label image" />
<img src="{{ image_url(child_image.name, 'macro') }}" alt="macro image" />
<img src="{{ image_url(child_image.name, 'thumbnail') }}"
alt="thumbnail image" />
<i class="mdi mdi-image text-sky-800"></i>
{{ child_image.name }}
</div>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect to remove this before the PR is merged, but this could be useful for reviewers testing the current GUI using the new image endpoints.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was handy. It shows that on TCGA-5N-A9KM-01Z-00-DX1.5197F750-D17F-459B-B74D-846F5F50F7B7.svs I'd expect to get a label image, but don't. Overall, this PR looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find a copy of the mentioned file on my local server under /collection/TCGA/square

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little bit confused about this image. There is indeed a label image, (Directory 5 when looking at the output of tifftools dump) but it doesn't have an ImageDescription tag pointing that out.

The value of NewSubfileType for this directory is 1, but that seems odd. According to tifftools, this bit represents "Image is a reduced-resolution version of another image in this TIFF file," but the label image isn't a reduced resolution version of any image in the file (that I'm aware of).

Additionally, other directories in the image, apart from the label and macro images, have NewSubfileType = 0. I would expect all but the highest resolution image to hava a value of 1. What's going on here? Is there another heuristic for finding a label image among the IFDs? If large image does this well, could you point me in that direction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on our conversation on Tuesday, I updated the logic in ad0302d

Comment on lines +13 to +29
def iter_ifds(
ifds: list[IFD],
tag_set=tifftools.constants.Tag,
) -> Generator[IFD, None, None]:
for ifd in ifds:
for tag_id, entry in ifd["tags"].items():
tag: tifftools.TiffTag = tifftools.constants.get_or_create_tag(
tag_id,
tagSet=tag_set,
datatype=tifftools.Datatype[entry["datatype"]],
)
if tag.isIFD():
# entry['ifds'] contains a list of lists
# see tifftools.read_tiff
for sub_ifds in entry.get("ifds", []):
yield from iter_ifds(sub_ifds, tag.get("tagset"))
yield ifd
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like an IFD iterator would be useful outside of the RedactionPlan classes. I think refactoring could be done in a follow up PR to keep the scope of this one down.

imagedephi/utils/tiff.py Outdated Show resolved Hide resolved
Comment on lines 94 to 99
def get_is_svs(image_path: Path) -> bool:
image_info = tifftools.read_tiff(image_path)
if tifftools.Tag.ImageDescription.value not in image_info["ifds"][0]:
return False
image_description = image_info["ifds"][0]["tags"][tifftools.Tag.ImageDescription.value]["data"]
return "aperio" in str(image_description).lower()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manthey We've recently seen svs images where associated image IFDs don't have an image description. Is the first IFD always going to be a tiled image? This function could just iterate over all IFDs and return True if any ImageDescription contains "Aperio"

@naglepuff naglepuff requested a review from manthey August 11, 2023 16:41
@naglepuff naglepuff marked this pull request as ready for review August 11, 2023 16:41
@manthey
Copy link
Contributor

manthey commented Sep 1, 2023

I've mirrored our logic for determining label/macro images in girder/large_image#1291.

@manthey
Copy link
Contributor

manthey commented Sep 1, 2023

This is looking good for what is here. @naglepuff Do you want to remove the UI integration and then merge this? Or should we create a fall-back reader for a tiled layer that doesn't decode with PIL-as-a-tiff first?

@naglepuff
Copy link
Collaborator Author

This is looking good for what is here. @naglepuff Do you want to remove the UI integration and then merge this? Or should we create a fall-back reader for a tiled layer that doesn't decode with PIL-as-a-tiff first?

I'll take out the UI elements and merge in the rest.

@naglepuff naglepuff merged commit d06ae30 into main Sep 13, 2023
@naglepuff naglepuff deleted the associated-imgs-preview branch September 13, 2023 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore showing macro, label images in UI
2 participants