Compare commits
35 Commits
Author | SHA256 | Date | |
---|---|---|---|
5334fc5429 | |||
cd93bd7c06 | |||
50d3c94106 | |||
2232cfb26c | |||
5f3a483b52 | |||
c227cfb603 | |||
1abc033a13 | |||
fa90e1b0cd | |||
fe328545e3 | |||
20dccd9cfd | |||
cebd87813d | |||
6ab3aabe56 | |||
53b15d3068 | |||
b14ea9eb46 | |||
c609e55ef7 | |||
0ac4534dfb | |||
bd0ebda4e1 | |||
|
3d111ede6d | ||
83eae9a81c | |||
|
5982b5798c | ||
|
fad76ec071 | ||
|
6da6689c19 | ||
8791af18d6 | |||
|
9f246a2081 | ||
8546cae505 | |||
|
e55b1044eb | ||
5f8f93b20a | |||
|
38cd82f524 | ||
|
687e11feef | ||
3c1a9cbce0 | |||
c461fc4905 | |||
|
87e5592fcb | ||
|
5cefc3bed1 | ||
cb3c253b4d | |||
|
6b38b7edb6 |
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:42c06ed74331174111dd42c89db774a13fc472abe18015f22c5aba80cddb7843
|
|
||||||
size 2203904
|
|
@@ -1,23 +0,0 @@
|
|||||||
From 11f7bd260137a18496bdfd00ddb742ef0cf2d2fd Mon Sep 17 00:00:00 2001
|
|
||||||
From: scaramallion <scaramallion@users.noreply.github.com>
|
|
||||||
Date: Mon, 16 Oct 2023 10:35:46 +1100
|
|
||||||
Subject: [PATCH 1/4] Fix Pillow raising AttributeError due to Image.mode being
|
|
||||||
read-only
|
|
||||||
|
|
||||||
Index: pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py
|
|
||||||
===================================================================
|
|
||||||
--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/pillow_handler.py
|
|
||||||
+++ pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py
|
|
||||||
@@ -129,7 +129,11 @@ def _decompress_single_frame(
|
|
||||||
image.tile[0][2],
|
|
||||||
(color_mode, ''),
|
|
||||||
)]
|
|
||||||
- image.mode = color_mode
|
|
||||||
+ # Pillow 10.1+ made Image.mode read-only
|
|
||||||
+ if hasattr(image, "_mode"):
|
|
||||||
+ image._mode = color_mode
|
|
||||||
+ else:
|
|
||||||
+ image.mode = color_mode
|
|
||||||
image.rawmode = color_mode
|
|
||||||
return image
|
|
||||||
|
|
@@ -1,101 +0,0 @@
|
|||||||
|
|
||||||
Index: pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py
|
|
||||||
===================================================================
|
|
||||||
--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/pillow_handler.py
|
|
||||||
+++ pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py
|
|
||||||
@@ -255,14 +255,14 @@ def get_pixeldata(ds: "Dataset") -> "num
|
|
||||||
if ds.PixelRepresentation == 1:
|
|
||||||
# Pillow converts signed data to unsigned
|
|
||||||
# so we need to undo this conversion
|
|
||||||
- arr -= 2**(bits_allocated - 1)
|
|
||||||
+ arr -= numpy.uint32(2**(bits_allocated - 1))
|
|
||||||
|
|
||||||
if shift:
|
|
||||||
arr = numpy.right_shift(arr, shift)
|
|
||||||
else:
|
|
||||||
# Corrections based on dataset elements
|
|
||||||
if ds.PixelRepresentation == 1:
|
|
||||||
- arr -= 2**(bits_allocated - 1)
|
|
||||||
+ arr -= numpy.uint32(2**(bits_allocated - 1))
|
|
||||||
|
|
||||||
if shift:
|
|
||||||
arr = numpy.right_shift(arr, shift)
|
|
||||||
Index: pydicom-2.4.4/pydicom/pixel_data_handlers/pylibjpeg_handler.py
|
|
||||||
===================================================================
|
|
||||||
--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/pylibjpeg_handler.py
|
|
||||||
+++ pydicom-2.4.4/pydicom/pixel_data_handlers/pylibjpeg_handler.py
|
|
||||||
@@ -66,11 +66,7 @@ except ImportError:
|
|
||||||
HAVE_PYLIBJPEG = False
|
|
||||||
|
|
||||||
if HAVE_PYLIBJPEG:
|
|
||||||
- try:
|
|
||||||
- from pylibjpeg.utils import get_pixel_data_decoders
|
|
||||||
- except ImportError:
|
|
||||||
- # Old import, deprecated in 1.2, removal in 2.0
|
|
||||||
- from pylibjpeg.pydicom.utils import get_pixel_data_decoders
|
|
||||||
+ from pylibjpeg.utils import get_pixel_data_decoders, Decoder
|
|
||||||
|
|
||||||
try:
|
|
||||||
import openjpeg
|
|
||||||
@@ -249,7 +245,7 @@ def generate_frames(
|
|
||||||
"elements are missing from the dataset: " + ", ".join(missing)
|
|
||||||
)
|
|
||||||
|
|
||||||
- decoder = _DECODERS[tsyntax]
|
|
||||||
+ decoder = cast(Decoder, _DECODERS[tsyntax])
|
|
||||||
LOGGER.debug(f"Decoding {tsyntax.name} encoded Pixel Data using {decoder}")
|
|
||||||
|
|
||||||
nr_frames = getattr(ds, "NumberOfFrames", 1)
|
|
||||||
@@ -260,7 +256,7 @@ def generate_frames(
|
|
||||||
bits_allocated = cast(int, ds.BitsAllocated)
|
|
||||||
|
|
||||||
for frame in generate_pixel_data_frame(ds.PixelData, nr_frames):
|
|
||||||
- arr = decoder(frame, pixel_module)
|
|
||||||
+ arr = decoder(frame, ds=pixel_module)
|
|
||||||
|
|
||||||
if (
|
|
||||||
tsyntax in [JPEG2000, JPEG2000Lossless]
|
|
||||||
Index: pydicom-2.4.4/pydicom/tests/test_encoders_pydicom.py
|
|
||||||
===================================================================
|
|
||||||
--- pydicom-2.4.4.orig/pydicom/tests/test_encoders_pydicom.py
|
|
||||||
+++ pydicom-2.4.4/pydicom/tests/test_encoders_pydicom.py
|
|
||||||
@@ -444,7 +444,7 @@ class TestRLEEncodeFrame:
|
|
||||||
assert ds.SamplesPerPixel == 3
|
|
||||||
assert ds.PixelRepresentation == 0
|
|
||||||
|
|
||||||
- arr = ref.newbyteorder('>')
|
|
||||||
+ arr = ref.view(ref.dtype.newbyteorder('>'))
|
|
||||||
assert id(arr) != id(ref)
|
|
||||||
assert arr.dtype == '>u2'
|
|
||||||
encoded = rle_encode_frame(arr)
|
|
||||||
Index: pydicom-2.4.4/pydicom/pixel_data_handlers/util.py
|
|
||||||
===================================================================
|
|
||||||
--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/util.py
|
|
||||||
+++ pydicom-2.4.4/pydicom/pixel_data_handlers/util.py
|
|
||||||
@@ -200,7 +200,7 @@ def apply_color_lut(
|
|
||||||
# IVs >= `first_map` are mapped by the Palette Color LUTs
|
|
||||||
# `first_map` may be negative, positive or 0
|
|
||||||
mapped_pixels = arr >= first_map
|
|
||||||
- clipped_iv[mapped_pixels] = arr[mapped_pixels] - first_map
|
|
||||||
+ clipped_iv[mapped_pixels] = arr[mapped_pixels] - np.int32(first_map)
|
|
||||||
# IVs > number of entries get set to last entry
|
|
||||||
np.clip(clipped_iv, 0, nr_entries - 1, out=clipped_iv)
|
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ def apply_modality_lut(arr: "np.ndarray"
|
|
||||||
# IVs >= `first_map` are mapped by the Modality LUT
|
|
||||||
# `first_map` may be negative, positive or 0
|
|
||||||
mapped_pixels = arr >= first_map
|
|
||||||
- clipped_iv[mapped_pixels] = arr[mapped_pixels] - first_map
|
|
||||||
+ clipped_iv[mapped_pixels] = arr[mapped_pixels] - np.int32(first_map)
|
|
||||||
# IVs > number of entries get set to last entry
|
|
||||||
np.clip(clipped_iv, 0, nr_entries - 1, out=clipped_iv)
|
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ def apply_voi(
|
|
||||||
# IVs >= `first_map` are mapped by the VOI LUT
|
|
||||||
# `first_map` may be negative, positive or 0
|
|
||||||
mapped_pixels = arr >= first_map
|
|
||||||
- clipped_iv[mapped_pixels] = arr[mapped_pixels] - first_map
|
|
||||||
+ clipped_iv[mapped_pixels] = arr[mapped_pixels] - np.int32(first_map)
|
|
||||||
# IVs > number of entries get set to last entry
|
|
||||||
np.clip(clipped_iv, 0, nr_entries - 1, out=clipped_iv)
|
|
||||||
|
|
Reference in New Issue
Block a user