Skip to content

Commit 82af7b0

Browse files
committed
Merge branch 'update-requirements'
2 parents 1ac1e51 + e236023 commit 82af7b0

File tree

3 files changed

+28
-45
lines changed

3 files changed

+28
-45
lines changed

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'gcp': [
5454
'google-auth>=1.6',
5555
'google-oauth>=1.0',
56-
]
56+
],
5757
},
5858
tests_require=[
5959
'mypy>=0.7',
@@ -62,10 +62,7 @@
6262
'pytest-flake8>=1.0',
6363
],
6464
install_requires=[
65-
'numpy>=1.13',
66-
'pillow>=5.0',
6765
'pydicom>=1.0',
6866
'requests>=2.18',
69-
'six>=1.11'
7067
]
7168
)

src/dicomweb_client/api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
import logging
66
import email
7-
import six
87
import xml.etree.ElementTree as ET
98
from collections import OrderedDict
109
from io import BytesIO
@@ -132,7 +131,7 @@ def _create_dataelement(
132131
else:
133132
elem_value = value
134133
else:
135-
if len(value) == 1 and isinstance(value[0], six.string_types):
134+
if len(value) == 1 and isinstance(value[0], str):
136135
elem_value = value[0].split('\\')
137136
else:
138137
elem_value = value
@@ -804,7 +803,7 @@ def _build_accept_header_field_value(
804803
)
805804
field_value_parts = []
806805
for media_type in media_types:
807-
if not isinstance(media_type, six.string_types):
806+
if not isinstance(media_type, str):
808807
raise TypeError(
809808
'Media type "{}" is not supported for '
810809
'requested resource'.format(media_type)
@@ -1523,7 +1522,7 @@ def _get_common_media_type(
15231522
raise ValueError('No acceptable media types provided.')
15241523
common_media_types = []
15251524
for item in media_types:
1526-
if isinstance(item, six.string_types):
1525+
if isinstance(item, str):
15271526
media_type = item
15281527
else:
15291528
media_type = item[0]
@@ -1677,7 +1676,7 @@ def _assert_uid_format(self, uid: str) -> None:
16771676
``"^[.0-9]+$"``
16781677
16791678
'''
1680-
if not isinstance(uid, six.string_types):
1679+
if not isinstance(uid, str):
16811680
raise TypeError('DICOM UID must be a string.')
16821681
pattern = re.compile('^[.0-9]+$')
16831682
if not pattern.search(uid):

src/dicomweb_client/cli.py

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import getpass
1010
from io import BytesIO
1111

12-
from PIL import Image
1312
import pydicom
14-
import numpy as np
1513

1614
from dicomweb_client.api import DICOMwebClient, load_json_dataset
1715
from dicomweb_client.log import configure_logging
@@ -440,16 +438,6 @@ def _save_metadata(data, directory, sop_instance_uid, prettify=False,
440438
json.dump(data, f, sort_keys=True)
441439

442440

443-
def _save_image(image, filename):
444-
logger.info('save pixel data to file "{}"'.format(filename))
445-
image.save(filename)
446-
447-
448-
def _show_image(image):
449-
logger.info('show pixel data')
450-
image.show()
451-
452-
453441
def _print_pixel_data(pixels):
454442
logger.info('print pixel data')
455443
print(pixels)
@@ -596,35 +584,34 @@ def _retrieve_instance_frames(client, args):
596584
image media types.
597585
'''
598586
pixel_data = client.retrieve_instance_frames(
599-
args.study_instance_uid, args.series_instance_uid,
600-
args.sop_instance_uid, args.frame_numbers,
587+
args.study_instance_uid,
588+
args.series_instance_uid,
589+
args.sop_instance_uid,
590+
args.frame_numbers,
601591
media_types=args.media_types,
602592
)
603593

604594
for i, data in enumerate(pixel_data):
605-
if args.save or args.show:
606-
try:
607-
image = Image.open(BytesIO(data))
608-
except Exception:
609-
try:
610-
import jpeg_ls
611-
image = jpeg_ls.decode(np.fromstring(data, dtype=np.uint8))
612-
except Exception:
613-
raise IOError(
614-
'Cannot load retrieved frame as an image.'
615-
)
616-
if args.save:
617-
filename = (
618-
'{sop_instance_uid}_{frame_number}.{extension}'.format(
619-
sop_instance_uid=args.sop_instance_uid,
620-
frame_number=args.frame_numbers[i],
621-
extension=image.format.lower()
622-
)
595+
if args.save:
596+
if data[:2] == b'\xFF\xD8': # SOI marker => JPEG
597+
if data[2:4] == b'\xFF\xF7': # SOF 55 marker => JPEG-LS
598+
extension = 'jls'
599+
else:
600+
extension = 'jpg'
601+
elif data[:2] == b'\xFF\x4F': # SOC marker => JPEG 2000
602+
extension = 'jp2'
603+
else:
604+
extension = 'dat'
605+
filename = (
606+
'{sop_instance_uid}_{frame_number}.{extension}'.format(
607+
sop_instance_uid=args.sop_instance_uid,
608+
frame_number=args.frame_numbers[i],
609+
extension=extension
623610
)
624-
filepath = os.path.join(args.output_dir, filename)
625-
_save_image(image, filepath)
626-
elif args.show:
627-
_show_image(image)
611+
)
612+
filepath = os.path.join(args.output_dir, filename)
613+
with open(filepath, 'bw') as fp:
614+
fp.write(data)
628615
else:
629616
_print_pixel_data(data)
630617

0 commit comments

Comments
 (0)