Skip to content

Commit

Permalink
Remove logic for determining transfer syntax
Browse files Browse the repository at this point in the history
wsidicom now determines the transfer syntax automatically, as of
version 0.14.0, so we don't need to do this anymore.

wsidicom also supports more transfer syntaxes as well, so the list
of transfer syntaxes we had are not complete now either. Just remove
this logic and let wsidicom take care of it.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Dec 1, 2023
1 parent 21d6864 commit 586519a
Showing 1 changed file with 1 addition and 54 deletions.
55 changes: 1 addition & 54 deletions sources/dicom/large_image_source_dicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from large_image.tilesource import FileTileSource
from large_image.tilesource.utilities import _imageToNumpy, _imageToPIL

from .dicom_tags import dicom_key_to_tag

dicomweb_client = None
pydicom = None
wsidicom = None
Expand Down Expand Up @@ -185,59 +183,8 @@ def _open_wsi_dicomweb(self, info):

wsidicom_client = wsidicom.WsiDicomWebClient(client)

# Identify the transfer syntax
transfer_syntax = self._identify_dicomweb_transfer_syntax(client,
study_uid,
series_uid)

# Open the WSI DICOMweb file
return wsidicom.WsiDicom.open_web(wsidicom_client, study_uid, series_uid,
requested_transfer_syntax=transfer_syntax)

def _identify_dicomweb_transfer_syntax(self, client, study_uid, series_uid):
# "client" is a dicomweb_client.DICOMwebClient

# This is how we select the JPEG type to return
# The available transfer syntaxes used by wsidicom may be found here:
# https://github.com/imi-bigpicture/wsidicom/blob/a2716cd6a443f4102e66e35bbce32b0e2ae72dab/wsidicom/web/wsidicom_web_client.py#L97-L109
# (we may need to update this if they add more options)
# FIXME: maybe this function better belongs upstream in `wsidicom`?
from pydicom.uid import JPEG2000, JPEG2000Lossless, JPEGBaseline8Bit, JPEGExtended12Bit

# Prefer the transfer syntaxes in this order.
transfer_syntax_preferred_order = [
JPEGBaseline8Bit,
JPEGExtended12Bit,
JPEG2000,
JPEG2000Lossless,
]
available_transfer_syntax_tag = dicom_key_to_tag('AvailableTransferSyntaxUID')

# Access the dicom web client, and search for one instance for the given
# study and series. Check the available transfer syntaxes.
result, = client.search_for_instances(
study_uid, series_uid,
fields=[available_transfer_syntax_tag], limit=1)

if available_transfer_syntax_tag in result:
available_transfer_syntaxes = result[available_transfer_syntax_tag]['Value']
for syntax in transfer_syntax_preferred_order:
if syntax in available_transfer_syntaxes:
return syntax
else:
# The server is not telling us which transfer syntaxes are available.
# Print a warning, default to JPEG2000, and hope for the best.
self.logger.warning(
'DICOMweb server is not communicating the available '
'transfer syntaxes. Assuming JPEG2000...',
)
return JPEG2000

msg = (
'Could not find an appropriate transfer syntax. '
f'Available transfer syntaxes are: {available_transfer_syntaxes}'
)
raise TileSourceError(msg)
return wsidicom.WsiDicom.open_web(wsidicom_client, study_uid, series_uid)

def __del__(self):
# If we have an _unstyledInstance attribute, this is not the owner of
Expand Down

0 comments on commit 586519a

Please sign in to comment.