Skip to content

Commit e236023

Browse files
committed
Remove unnecessary dependencies
1 parent 82389e8 commit e236023

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',
@@ -63,10 +63,7 @@
6363
'tox>=3.13',
6464
],
6565
install_requires=[
66-
'numpy>=1.13',
67-
'pillow>=5.0',
6866
'pydicom>=1.0',
6967
'requests>=2.18',
70-
'six>=1.11'
7168
]
7269
)

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
@@ -885,7 +884,7 @@ def _build_accept_header_field_value(
885884
)
886885
field_value_parts = []
887886
for media_type in media_types:
888-
if not isinstance(media_type, six.string_types):
887+
if not isinstance(media_type, str):
889888
raise TypeError(
890889
'Media type "{}" is not supported for '
891890
'requested resource'.format(media_type)
@@ -1604,7 +1603,7 @@ def _get_common_media_type(
16041603
raise ValueError('No acceptable media types provided.')
16051604
common_media_types = []
16061605
for item in media_types:
1607-
if isinstance(item, six.string_types):
1606+
if isinstance(item, str):
16081607
media_type = item
16091608
else:
16101609
media_type = item[0]
@@ -1758,7 +1757,7 @@ def _assert_uid_format(self, uid: str) -> None:
17581757
``"^[.0-9]+$"``
17591758
17601759
'''
1761-
if not isinstance(uid, six.string_types):
1760+
if not isinstance(uid, str):
17621761
raise TypeError('DICOM UID must be a string.')
17631762
pattern = re.compile('^[.0-9]+$')
17641763
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
@@ -436,16 +434,6 @@ def _save_metadata(data, directory, sop_instance_uid, prettify=False,
436434
json.dump(data, f, sort_keys=True)
437435

438436

439-
def _save_image(image, filename):
440-
logger.info('save pixel data to file "{}"'.format(filename))
441-
image.save(filename)
442-
443-
444-
def _show_image(image):
445-
logger.info('show pixel data')
446-
image.show()
447-
448-
449437
def _print_pixel_data(pixels):
450438
logger.info('print pixel data')
451439
print(pixels)
@@ -592,35 +580,34 @@ def _retrieve_instance_frames(client, args):
592580
image media types.
593581
'''
594582
pixel_data = client.retrieve_instance_frames(
595-
args.study_instance_uid, args.series_instance_uid,
596-
args.sop_instance_uid, args.frame_numbers,
583+
args.study_instance_uid,
584+
args.series_instance_uid,
585+
args.sop_instance_uid,
586+
args.frame_numbers,
597587
media_types=args.media_types,
598588
)
599589

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

0 commit comments

Comments
 (0)