|
1 | | -# pylibjpeg-rle |
2 | | -Fast RLE decoding plugin for pylibjpeg |
| 1 | + |
| 2 | +## pylibjpeg-rle |
| 3 | + |
| 4 | +A fast DICOM RLE decoding plugin for pylibjpeg, written in Rust with a Python 3.6+ wrapper. |
| 5 | + |
| 6 | +Linux, OSX and Windows are all supported. |
| 7 | + |
| 8 | +### Installation |
| 9 | +#### Installing the current release |
| 10 | +```bash |
| 11 | +pip install pylibjpeg-rle |
| 12 | +``` |
| 13 | +#### Installing the development version |
| 14 | + |
| 15 | +Make sure [Python](https://www.python.org/), [Git](https://git-scm.com/) and |
| 16 | +[Rust](https://www.rust-lang.org/) are installed. For Windows, you also need to install |
| 17 | +[Microsoft's C++ Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16). |
| 18 | +```bash |
| 19 | +git clone https://github.com/pydicom/pylibjpeg-rle |
| 20 | +cd pylibjpeg-rle |
| 21 | +python -m setup.py develop |
| 22 | +``` |
| 23 | + |
| 24 | +### Supported Transfer Syntaxes |
| 25 | +#### Decoding |
| 26 | +| UID | Description | |
| 27 | +| --- | --- | |
| 28 | +| 1.2.840.10008.1.2.5 | RLE Lossless | |
| 29 | + |
| 30 | +### Benchmarks |
| 31 | +#### Decoding |
| 32 | + |
| 33 | +Time per 1000 decodes, pydicom's NumPy RLE handler vs. pylibjpeg-rle |
| 34 | + |
| 35 | +| Dataset | Pixels | Bytes | NumPy | pylibjpeg-rle | |
| 36 | +| --- | --- | --- | --- | --- | |
| 37 | +| OBXXXX1A_rle.dcm | 480,000 | 480,000 | 4.89 s | 0.79 s | |
| 38 | +| OBXXXX1A_rle_2frame.dcm | 960,000 | 960,000 | 9.89 s | 1.65 s | |
| 39 | +| SC_rgb_rle.dcm | 10,000 | 30,000 | 0.20 s | 0.15 s | |
| 40 | +| SC_rgb_rle_2frame.dcm | 20,000 | 60,000 | 0.32 s | 0.18 s | |
| 41 | +| MR_small_RLE.dcm | 4,096 | 8,192 | 0.35 s | 0.13 s | |
| 42 | +| emri_small_RLE.dcm | 40,960 | 81,920 | 1.13 s | 0.28 s | |
| 43 | +| SC_rgb_rle_16bit.dcm | 10,000 | 60,000 | 0.33 s | 0.17 s | |
| 44 | +| SC_rgb_rle_16bit_2frame.dcm | 20,000 | 120,000 | 0.56 s | 0.21 s | |
| 45 | +| rtdose_rle_1frame.dcm | 100 | 400 | 0.12 s | 0.13 s | |
| 46 | +| rtdose_rle.dcm | 1,500 | 6,000 | 0.53 s | 0.26 s | |
| 47 | +| SC_rgb_rle_32bit.dcm | 10,000 | 120,000 | 0.56 s | 0.19 s | |
| 48 | +| SC_rgb_rle_32bit_2frame.dcm | 20,000 | 240,000 | 1.03 s | 0.28 s | |
| 49 | + |
| 50 | +### Usage |
| 51 | +#### With pylibjpeg and pydicom |
| 52 | + |
| 53 | +Because pydicom defaults to the NumPy RLE decoder, you must specify the use |
| 54 | +of pylibjpeg when decompressing: |
| 55 | +*Pixel Data*: |
| 56 | +```python |
| 57 | +from pydicom import dcmread |
| 58 | +from pydicom.data import get_testdata_file |
| 59 | + |
| 60 | +ds = dcmread(get_testdata_file("OBXXXX1A_rle.dcm")) |
| 61 | +ds.decompress("pylibjpeg") |
| 62 | +arr = ds.pixel_array |
| 63 | +``` |
| 64 | + |
| 65 | +Alternatively you can use the included functions to decode a given dataset: |
| 66 | +```python |
| 67 | +from rle import pixel_array, generate_frames |
| 68 | + |
| 69 | +# Return the entire Pixel Data as an ndarray |
| 70 | +arr = pixel_array(ds) |
| 71 | + |
| 72 | +# Generator function that only processes 1 frame at a time, |
| 73 | +# may help reduce memory usage when dealing with large Pixel Data |
| 74 | +for arr in generate_frames(ds): |
| 75 | + print(arr.shape) |
| 76 | +``` |
0 commit comments