Python bindings for a fast RLE decoder/encoder, with a focus on use as a plugin for pylibjpeg
Project description
pylibjpeg-rle
A fast DICOM (PackBits) RLE plugin for pylibjpeg, written in Rust with a Python 3.7+ wrapper.
Linux, MacOS and Windows are all supported.
Installation
Installing the current release
pip install pylibjpeg-rle
Installing the development version
Make sure Python, Git and Rust are installed. For Windows, you also need to install Microsoft's C++ Build Tools.
git clone https://github.com/pydicom/pylibjpeg-rle
cd pylibjpeg-rle
python -m pip install .
Supported Transfer Syntaxes
UID | Description | Decoding | Encoding |
---|---|---|---|
1.2.840.10008.1.2.5 | RLE Lossless | Yes | Yes |
Usage
Decoding
With pylibjpeg
from pydicom import dcmread
from pydicom.data import get_testdata_file
ds = dcmread(get_testdata_file("OBXXXX1A_rle.dcm"))
arr = ds.pixel_array
Standalone with pydicom
Alternatively you can use the included functions to decode a given dataset:
from rle import pixel_array, generate_frames
# Return the entire Pixel Data as an ndarray
arr = pixel_array(ds)
# Generator function that only processes 1 frame at a time,
# may help reduce memory usage when dealing with large Pixel Data
for arr in generate_frames(ds):
print(arr.shape)
Encoding
Standalone with pydicom
Convert uncompressed pixel data to RLE encoding and save:
from pydicom import dcmread
from pydicom.data import get_testdata_file
from pydicom.uid import RLELossless
from rle import pixel_data
# Get the uncompressed pixel data
ds = dcmread(get_testdata_file("OBXXXX1A.dcm"))
arr = ds.pixel_array
# RLE encode and encapsulate `arr`
ds.PixelData = pixel_data(arr, ds)
# Set the correct *Transfer Syntax UID*
ds.file_meta.TransferSyntaxUID = RLELossless
ds.save_as('as_rle.dcm')
Benchmarks
Decoding
Time per 1000 decodes, pydicom's default RLE handler vs. pylibjpeg-rle
Dataset | Pixels | Bytes | pydicom | pylibjpeg-rle |
---|---|---|---|---|
OBXXXX1A_rle.dcm | 480,000 | 480,000 | 4.89 s | 0.79 s |
OBXXXX1A_rle_2frame.dcm | 960,000 | 960,000 | 9.89 s | 1.65 s |
SC_rgb_rle.dcm | 10,000 | 30,000 | 0.20 s | 0.15 s |
SC_rgb_rle_2frame.dcm | 20,000 | 60,000 | 0.32 s | 0.18 s |
MR_small_RLE.dcm | 4,096 | 8,192 | 0.35 s | 0.13 s |
emri_small_RLE.dcm | 40,960 | 81,920 | 1.13 s | 0.28 s |
SC_rgb_rle_16bit.dcm | 10,000 | 60,000 | 0.33 s | 0.17 s |
SC_rgb_rle_16bit_2frame.dcm | 20,000 | 120,000 | 0.56 s | 0.21 s |
rtdose_rle_1frame.dcm | 100 | 400 | 0.12 s | 0.13 s |
rtdose_rle.dcm | 1,500 | 6,000 | 0.53 s | 0.26 s |
SC_rgb_rle_32bit.dcm | 10,000 | 120,000 | 0.56 s | 0.19 s |
SC_rgb_rle_32bit_2frame.dcm | 20,000 | 240,000 | 1.03 s | 0.28 s |
Encoding
Time per 1000 encodes, pydicom's default RLE handler vs. pylibjpeg-rle
Dataset | Pixels | Bytes | pydicom | pylibjpeg-rle |
---|---|---|---|---|
OBXXXX1A.dcm | 480,000 | 480,000 | 30.7 s | 1.36 s |
SC_rgb.dcm | 10,000 | 30,000 | 1.80 s | 0.09 s |
MR_small.dcm | 4,096 | 8,192 | 2.29 s | 0.04 s |
SC_rgb_16bit.dcm | 10,000 | 60,000 | 3.57 s | 0.17 s |
rtdose_1frame.dcm | 100 | 400 | 0.19 s | 0.003 s |
SC_rgb_32bit.dcm | 10,000 | 120,000 | 7.20 s | 0.33 s |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pylibjpeg-rle-1.3.0.tar.gz
(26.2 kB
view hashes)
Built Distributions
Close
Hashes for pylibjpeg_rle-1.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2e238722d63c567a0bfadc67251300d3b0c60cb27533cc2b7e198146a7f9c45 |
|
MD5 | 1fa5b76f6b4adb5b3a660054a855d156 |
|
BLAKE2b-256 | 56dd9b65b80bafa0da2b54c91b6e005b0e015a49a8647df923b1ed0374c716c9 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a5f020e565fde8e9340c625c620d88be7468bfaa53d0b469e965409f1728cfe |
|
MD5 | bd57b0e40fc8111957faadac3bf71e48 |
|
BLAKE2b-256 | bd90136f9640e7900f02a4cae5951b574ebf91af4957723fc46804bedd0c378d |
Close
Hashes for pylibjpeg_rle-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a11a25b7685ef5c72353180a46acb7f885aa66d880719a6f01e9dd8b63ec9314 |
|
MD5 | 28152f3afe7bcd8c5f975765ff2a1480 |
|
BLAKE2b-256 | 8811a776191a7f800ef6de84d7c84a97d8ae2cc57575ceaeaefabe06e3df1083 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dc4aba0e4bb79bd2b3f326b9370d685a71f925fc2ece9a7b252bba4cc4e53fb |
|
MD5 | c00b7c0d52e75e782e496fc300639489 |
|
BLAKE2b-256 | 91fc83fae2951323d09e890b2691ea20635bedb099ef02fcd11b2a8f6346f0c8 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7695786604c3803fbeb172a82700412e4e8f3fe2595e1434169c6a564afb7e70 |
|
MD5 | 2784b7c6db257b6c12b6549bd18b4d09 |
|
BLAKE2b-256 | ac059a90874ec2363a1a5859cae372951a2ad8ece419629cc5e3910805c75600 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54b8f2380a262154463d8726edf86085520022650fddcb70c00a34881d9c76a5 |
|
MD5 | 9c2e0bc57deb2bb54c5fec47ca709499 |
|
BLAKE2b-256 | da83829cf0270a43df742ddf071240021fdf7da4cf831bd40dfa4a72949874c2 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9158c3ffd80e68b12d5ce665498eabfe608cea8f2fd0664ec82d33a7ebcb7a |
|
MD5 | 5ac2309174c40f2f110b02ebcc66ee70 |
|
BLAKE2b-256 | 32aca5fa23a17b0182ad33168bcae558f0b3be87ff749ebdc4529c370e9a17d5 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32104916e315887e9a76925ae777be42cc491a88b6f2b1f3b09ce13b7b0e7063 |
|
MD5 | 80b0ff5ef31f572e7ddfe0e069242fb7 |
|
BLAKE2b-256 | 67d3fd7234dc30ec06f6dce5985a8a5a3dccb3d71287a51e2bf42756677078aa |
Close
Hashes for pylibjpeg_rle-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 995da4b556bc029415729fa9b20e4207a7a55ac2343c6ae16d7743b3b606f8b8 |
|
MD5 | 5b9b790ecc0f230aa5039bd607f4f947 |
|
BLAKE2b-256 | f75efdbafacb96cbfa49c02ac7be08ad02d5dd92bd1d4fddccc582e93ba25383 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2983cafd097455d226172f8286fadea626631d79be9e58f69c1d3586fb8f242e |
|
MD5 | a4111b14d4c3e1a30d8cca316b5ebb79 |
|
BLAKE2b-256 | 796847fd2ecafc19d828a387508d7ea8bb4e3c5fe65815c8fef547d4b1a70cb0 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9896fdd3883affb2e83c71ef3814d6ac494dc698da80582ba93ca32236b769ba |
|
MD5 | fd1de7ffd42a6d04ff9f87b708bf89f7 |
|
BLAKE2b-256 | c9a11a6b146b6e6ffa642726aa230b72f2750de31513dc591ec9205885ab5475 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db4d9b111e0b1410fd5ecea30e85c10a505437cd2bb40763dd41d6365df98d90 |
|
MD5 | 447f611568142c780ecbde295617ca58 |
|
BLAKE2b-256 | 944d8fe509ea27c0747ced4cc3a07226a46d276f85b055da110cb45b96c0d3f6 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe00c72974ff3e071cf735cf020b379d67ddc51e7d841fe7397b43a43d2d68f |
|
MD5 | 6410db6a553e4ff0bbd8e719df4cc7c9 |
|
BLAKE2b-256 | 3dfecff88b4004b6fabfc5662d5855ba4118c4619c9dad9459d595f0cea443e9 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e0641e975f1d91b8b31644f74a4aabe6ba53536aac7e71b2ec7bd7dee80216 |
|
MD5 | 10613db01da59dbd2fec5795f7b8d9b4 |
|
BLAKE2b-256 | da87413398d87c3c6ac47eecf5069c37147944f990f00821aef930ea55a55b3f |
Close
Hashes for pylibjpeg_rle-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3712ca118da9f73b2929197bf13c508358d83384df26fdbbca28a0a5cbce94c9 |
|
MD5 | cec4cc67fe1aacdd9f42ef38ecf6fb78 |
|
BLAKE2b-256 | a54231cf87395f6a6c043b642af66d1c459521c1103703882fe8781e3213d4c5 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fbc292bf6f4ec7cb55b9aa24aae4dda8a00d474e819172c8aa34413ec7ccc26 |
|
MD5 | f41c886783135338aeb1fcc931a5cfe9 |
|
BLAKE2b-256 | 5337e4b07e91b2f3a11baffdc8185ef6b38c617cb02c6fba63a1d67d28fe8b7c |
Close
Hashes for pylibjpeg_rle-1.3.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5267b4a9095cd2c8962ac6ff6c10902e35f9057ed1e4e61dc88fb2dfdbfeacfd |
|
MD5 | 2e8d3a22836cc1a55e94ad42c2e8be7a |
|
BLAKE2b-256 | 2b0d02ce8e6b91a1d28f2f29f2514f09c8f727b3390df11825c60f3475f8e841 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f58d3d88dfe11727b12cf7c86229870b550c05b4b18beaacfd01e156abe2d436 |
|
MD5 | 0a77c5aa17e0f15c4ff3935f17c3ebfe |
|
BLAKE2b-256 | de6cc530ba83ecca699587479a5523605640ccb4e20212b32d9bd388918c361a |
Close
Hashes for pylibjpeg_rle-1.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fadbbc711ebc797dbdfa57ca659af56d606f0bf22d3f8b253631fcb812354f9 |
|
MD5 | 41e993d809e5568876a349348c40a236 |
|
BLAKE2b-256 | 4f1164efdc58947d47a0df80c32f622c5912429419b3e82e3cc5040508c1b08c |
Close
Hashes for pylibjpeg_rle-1.3.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1527fdc363ff647b2211e248e1f469e19a869db25046fec11b0c6388eb6a25ac |
|
MD5 | a0759af60e395557a706c97fcd181de2 |
|
BLAKE2b-256 | 73901102f3f5b99f5e55b0ea6c1990bfc5db7369403f3eac6e35dede0decc32f |
Close
Hashes for pylibjpeg_rle-1.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7bd1edcc7ff7ca9fa45735bed12cc503f38fad111812ef5147bb8f5904883b4 |
|
MD5 | b105a6d2821bb213e35b34f674544b23 |
|
BLAKE2b-256 | 3e28050f360f031a48b718596727f43812f22b01ce3f5b854041272b7c17b721 |
Close
Hashes for pylibjpeg_rle-1.3.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f240cbf68d32b95f3d27633c4815608f1343acfec608653deaaf52e68a4ca5 |
|
MD5 | bfec5c9b629cc22b15efbc666d4ac0c2 |
|
BLAKE2b-256 | 5d4f6206c9822a915c824db3fa07071a7b51c63deddb239881074a7463df69eb |
Close
Hashes for pylibjpeg_rle-1.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83736cf4ba987543d02815ab7c44dc62297dca423d2120b273c9e9442451f560 |
|
MD5 | 75549f57949e9593744e22bab7d997b4 |
|
BLAKE2b-256 | 647e654259b3c4d1d422b9ebdcaa12b966a8e74958a3634ae73879dec0b5026a |