You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-21Lines changed: 42 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
6
6
## pylibjpeg
7
7
8
-
A Python 3.6+ framework for decoding JPEG images and RLE datasets, with a focus on providing support for [pydicom](https://github.com/pydicom/pydicom).
8
+
A Python 3.6+ framework for decoding JPEG images and decoding/encoding RLE datasets, with a focus on providing support for [pydicom](https://github.com/pydicom/pydicom).
If you're not sure what the dataset's *Transfer Syntax UID* is, it can be
53
53
determined with:
@@ -65,8 +65,9 @@ determined with:
65
65
66
66
67
67
### Usage
68
-
#### With pydicom
69
-
Assuming you already have *pydicom* v2.1+ and suitable plugins installed:
68
+
#### Decoding
69
+
##### With pydicom
70
+
Assuming you have *pydicom* v2.1+ and suitable plugins installed:
70
71
71
72
```python
72
73
from pydicom import dcmread
@@ -101,7 +102,7 @@ frames = generate_frames(ds)
101
102
arr =next(frames)
102
103
```
103
104
104
-
#### Standalone JPEG decoding
105
+
#####Standalone JPEG decoding
105
106
You can also just use *pylibjpeg* to decode JPEG images to a [numpy ndarray](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html), provided you have a suitable plugin installed:
106
107
```python
107
108
from pylibjpeg import decode
@@ -117,3 +118,23 @@ with open('filename.jpg', 'rb') as f:
117
118
withopen('filename.jpg', 'rb') as f:
118
119
arr = decode(f.read())
119
120
```
121
+
122
+
#### Encoding
123
+
##### With pydicom
124
+
125
+
Assuming you have *pydicom* v2.2+ and suitable plugins installed:
126
+
127
+
```python
128
+
from pydicom import dcmread
129
+
from pydicom.data import get_testdata_file
130
+
from pydicom.uid import RLELossless
131
+
132
+
ds = dcmread(get_testdata_file("CT_small.dcm"))
133
+
134
+
# Encode in-place using RLE Lossless and update the dataset
135
+
# Updates the Pixel Data, Transfer Syntax UID and Planar Configuration
Copy file name to clipboardExpand all lines: docs/plugins.md
+95-12Lines changed: 95 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,25 +24,38 @@ setup(
24
24
25
25
#### Decoder function signature
26
26
27
-
The pixel data decoding function will be passed two arguments; a single encoded
28
-
image frame as [bytes](https://docs.python.org/3/library/stdtypes.html#bytes) and a *pydicom*[Dataset](https://pydicom.github.io/pydicom/stable/reference/generated/pydicom.dataset.Dataset.html) object containing the (0028,eeee) elements corresponding to the pixel data. The function should return the decoded pixel data as a one-dimensional numpy [ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) of `'uint8'`:
27
+
The pixel data decoding function will be passed two required parameters:
28
+
29
+
**src*: a single encoded image frame as [bytes](https://docs.python.org/3/library/stdtypes.html#bytes)
30
+
**ds*: a *pydicom*[Dataset](https://pydicom.github.io/pydicom/stable/reference/generated/pydicom.dataset.Dataset.html) object containing the (0028,eeee) elements corresponding to the pixel data
31
+
32
+
The function should return the decoded pixel data as a one-dimensional numpy [ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) of little-endian ordered `'uint8'`, with the data ordered from left-to-right, top-to-bottom (i.e. the first byte corresponds to the upper left pixel and the last byte corresponds to the lower-right pixel) and a planar configuration that matches
33
+
the requirements of the transfer syntax:
29
34
30
35
```python
31
-
defmy_pixel_data_decoder(data, ds):
32
-
"""Return the encoded `data` as an unshaped numpy ndarray of uint8.
36
+
defmy_pixel_data_decoder(
37
+
src: bytes, ds: pydicom.dataset.Dataset, **kwargs
38
+
) -> numpy.ndarray:
39
+
"""Return the encoded `src` as an unshaped numpy ndarray of uint8.
40
+
41
+
.. versionchanged:: 1.3
42
+
43
+
Added requirement to return little-endian ordered data by default.
33
44
34
45
Parameters
35
46
----------
36
-
data : bytes
47
+
src : bytes
37
48
A single frame of the encoded *Pixel Data*.
38
49
ds : pydicom.dataset.Dataset
39
50
A dataset containing the group ``0x0028`` elements corresponding to
40
51
the *Pixel Data*.
52
+
kwargs
53
+
Optional keyword parameters for the decoder.
41
54
42
55
Returns
43
56
-------
44
57
numpy.ndarray
45
-
A 1-dimensional ndarray of 'uint8' containing the decoded pixel data.
58
+
A 1-dimensional ndarray of 'uint8' containing the little-endian ordered decoded pixel data.
46
59
"""
47
60
# Decoding happens here
48
61
```
@@ -78,19 +91,18 @@ Possible entry points for JPEG decoding are:
78
91
79
92
#### Decoder function signature
80
93
81
-
The JPEG decoding function will be passed the encoded JPEG *data* as
82
-
[bytes](https://docs.python.org/3/library/stdtypes.html#bytes) and a
94
+
The JPEG decoding function will be passed the encoded JPEG *data* as [bytes](https://docs.python.org/3/library/stdtypes.html#bytes) and a
83
95
[dict](https://docs.python.org/3/library/stdtypes.html#dict) containing keyword arguments passed to the function. The function should return the decoded image data as a numpy [ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) with a dtype and shape matching the image format and dimensions:
84
96
85
97
```python
86
-
defmy_jpeg_decoder(data, **kwarg):
87
-
"""Return the encoded JPEG `data` as an numpy ndarray.
98
+
defmy_jpeg_decoder(src, **kwargs):
99
+
"""Return the encoded JPEG `src` as an numpy ndarray.
Plugins that encode DICOM *Pixel Data* should register their encoding functions using the corresponding *Transfer Syntax UID* as the entry point name. For example, if the `my_plugin` plugin supported encoding *RLE Lossless* (1.2.840.10008.1.2.5) with the encoding function `encode_rle_lossless()` then it should include the following in its `setup.py`:
0 commit comments