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 setup.py develop
Supported Transfer Syntaxes
UID | Description | Decoding | Encoding |
---|---|---|---|
1.2.840.10008.1.2.5 | RLE Lossless | Yes | Yes |
Usage
Decoding
With pylibjpeg
Because pydicom defaults to its own RLE decoder you must specify the use of pylibjpeg when decompressing:
from pydicom import dcmread
from pydicom.data import get_testdata_file
ds = dcmread(get_testdata_file("OBXXXX1A_rle.dcm"))
ds.decompress("pylibjpeg")
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
Built Distributions
Hashes for pylibjpeg_rle-1.2.0-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60e6c67b8229456103ac2744938fbf36a4b0aea3fe903c18b4a5f0e24e4e3e7e |
|
MD5 | 0c77692eed536999de0aaf7e2d7aef96 |
|
BLAKE2b-256 | 08a3be63c2bd34d1119212fb0e7ab56b1741f372252fd0394db142746b8e6078 |
Hashes for pylibjpeg_rle-1.2.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c0eebe9d7939e279f55ae0a0cfbdc600819dc8abd36c1b29914b5e85a4dddf4 |
|
MD5 | d27b62492e620ad34406e53fbb2979a1 |
|
BLAKE2b-256 | f4dbedd357f53c82dde2d8b25c17eef816c43010ed0552114b544fc5530304dd |
Hashes for pylibjpeg_rle-1.2.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7313409aae3a0414bb5f03da368c20deccfa8840bccef92f1653b32d836ed670 |
|
MD5 | 600e172630fa2a6c2171498536f074cd |
|
BLAKE2b-256 | c7283bfc50a466631bdf23d2022f26686a3f2b027a03029efcd736daacd1c1df |
Hashes for pylibjpeg_rle-1.2.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef29a3af67195fa07f9bf6d47cfd850b05299d305dc1b9a4654a2411be89d68c |
|
MD5 | 3f3bdb0f7671c57c357c22de25140a83 |
|
BLAKE2b-256 | 2cd30ab7093987b08b0c3d8ff689281f48c295de99067febd8df59702500892c |
Hashes for pylibjpeg_rle-1.2.0-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da22742a26c48b4bf7b5be730a3940bca608ea3ec5babd1c2a30fec6a42c0e1 |
|
MD5 | 11cf4082fefd3e90ffa49d9cdebd9cb3 |
|
BLAKE2b-256 | 84a2768a2131b8990021cd028df8bbe9a0b187d0adcdb67f2c52d73f4e671a4f |
Hashes for pylibjpeg_rle-1.2.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7535a80feef2c70650b7c0072e06f66f1cdbc2602617f4d06f2509cfead4cdc |
|
MD5 | 5a90abe35b7136bb7ce91c0bde513253 |
|
BLAKE2b-256 | c256c9f16b5618d6a9558cb56fa509b08c6f58dab102b5ddd7370b918f1dfa5c |
Hashes for pylibjpeg_rle-1.2.0-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6785dbef1819e1110c741b8056df05204991968b1de951f8073c7cf2cfec7ed4 |
|
MD5 | a154df039210ee148d79925142f7b3b1 |
|
BLAKE2b-256 | edb3a29787697d586fa2bbe8b316ecb253ff0073e992feefe2190abfb7b90976 |
Hashes for pylibjpeg_rle-1.2.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c88b6e2fdd2027ebb7ff499caac7bbc7debbdaf1b4c8df7dd2ad99f71fe15f5 |
|
MD5 | 1001044b9a5c5f260da36d5fb740ad6f |
|
BLAKE2b-256 | adcf6efde25998de374deea3699540bb1fa488688de0c608a965cb4f8c66495d |
Hashes for pylibjpeg_rle-1.2.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c622a15323ed21bbd3277dade7593cf893110d1337ef6ee8a0c67c6832bcb078 |
|
MD5 | 032219e714584acf1cef8b8603be93c4 |
|
BLAKE2b-256 | c8a4f528874f485dc8e705c2f3a88e001d4f8a164b6b6e186c08e15cbd54c522 |
Hashes for pylibjpeg_rle-1.2.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d65a23790a4df49c73912444b7483ddc77ec349fb2b3429ebe74a6beaa1afc |
|
MD5 | 19f87311e08b14d011efc6a8602d6bab |
|
BLAKE2b-256 | 383cd01909bd96cb11d3ad796c5348d748562cc0fd2b942276317335084b6dcb |
Hashes for pylibjpeg_rle-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aedd21b5665e0aa220343d7cd848d65f8b8745f40964df9592374477f42870c |
|
MD5 | 20ba3bf48b933e780ee260ee1007fd00 |
|
BLAKE2b-256 | cc4850c7b4e520d3f770d50ddfd35d1861cee33f66145dbcdd3efb462b3d3fd8 |
Hashes for pylibjpeg_rle-1.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5457333a51343ebbfb77e0eb9f5ba11e86b7c37b2013bdef6f17964053129fe |
|
MD5 | ed8b226e98decb51a97c578d599df183 |
|
BLAKE2b-256 | 68e27377b38f946ba2ba1998fd2b42d4c6a535ca2400fb5b44c539f3c5512aee |
Hashes for pylibjpeg_rle-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd7dfbf1d813ff0b216e3ab9af5575e36b7129940357b625123336a77631e58 |
|
MD5 | d99e1d637df5bfcf1163fabd0d8be4da |
|
BLAKE2b-256 | a68090b2da239d4459aa4c6b5fcd16dc3553429c1bd6d453589a40f94842cec1 |
Hashes for pylibjpeg_rle-1.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 967a50880629c09a87bb48733f17cd11ee9c29cd7ee9f4fb6f7ffe61a67ea678 |
|
MD5 | 6a547c88bdac100b88ba046f13ad4acc |
|
BLAKE2b-256 | 2076db259039dfbf0709ad4b8c984f142c2a90f7c0db7b85e3278d8b10cccfbc |
Hashes for pylibjpeg_rle-1.2.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04737d3c9690ad7c93dafe2e2b2315203ee863ec8d6f75f3d2e1fbb175f0e16b |
|
MD5 | da9d35a5bb47953961322bb88dec4827 |
|
BLAKE2b-256 | d0a0fb45d0dd4bc0e0d1f308d843b8038511fd42644b78eaffbd206d2d4a7c43 |
Hashes for pylibjpeg_rle-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e776be10d4a92b12e25668c0b4ea7db1eaad32962b603b83b2952d6d23913e04 |
|
MD5 | 63ab0f57cc3f142f0af5c90ea4f1266e |
|
BLAKE2b-256 | 7bf20546e37caaa19ab04ebfa75757a85c75be6a283cdc14f26fadfe94c22ca8 |
Hashes for pylibjpeg_rle-1.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6be4cae61a43d7d26e5eff14eabb2d1619046e2e623f9c3e893641940462e755 |
|
MD5 | 40f77252afc01ea8e23829a8730ed9bf |
|
BLAKE2b-256 | 98a3196af15959711e8fbcbde3a095c0364db860dc63684eb131d5d4f5fdd0af |
Hashes for pylibjpeg_rle-1.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b15f62d8620cf0d6df15bb750542b0f5e1609ed1347e81e00996c08c38dc86 |
|
MD5 | 669ab018eb5a86ee1222f03132bee1b2 |
|
BLAKE2b-256 | a4b320d1a53d2055f8d35ba0ea4524f3f1b8f85336d8ea4ab822474975857520 |
Hashes for pylibjpeg_rle-1.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dec5c7d513254da622935d6bcaa0a8fd5cdd422916bdf1f7a824a646e1ad7dd8 |
|
MD5 | 60dbcac1781a9467e5dfd19e5780164c |
|
BLAKE2b-256 | f0db8019ac221882e95e922c2c79cb57442fc956809ab7f0f8dcb039d96f6f8c |
Hashes for pylibjpeg_rle-1.2.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551571a6e278a35b0dd9b61b1183ad8944a96b3114813bd58a31ddb8fcb20063 |
|
MD5 | 414c22bd12a4840c218402dcd65a867e |
|
BLAKE2b-256 | 7340647ca36bb39287e7f17063d2428beabce632af8f3fabd88880f289f67361 |
Hashes for pylibjpeg_rle-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8df68c108d199a9219072cf57b3d783290772177c08cce7c3af9239eb327f4e |
|
MD5 | d5e0978e6d88e524652a8d6ef9e7d01c |
|
BLAKE2b-256 | 8673c616416a3342fd7374f2b03fbf745b442a8bba2020e0c3343f728602716f |
Hashes for pylibjpeg_rle-1.2.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7092fecc3fd4c035dc978f9d4fc71da0e85b3de3df57beb5381908e6cc282da2 |
|
MD5 | 39c3f1684012b4ea132462daaa502ebc |
|
BLAKE2b-256 | 45fff6ed85dd45692e6386bf49b7a9d7ce1fa0ab43ff201f064059e3be369419 |
Hashes for pylibjpeg_rle-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66ec187514a44d86a73582e03b8032efc19dc02083c85520a8567b45466a96a6 |
|
MD5 | 8d36540ef1313a47d168de47334422a6 |
|
BLAKE2b-256 | 26fa67ac2c4a1f7bdf1e93c7ff46407e4997637b5b76c847a7a6ff7e60cf2ca3 |
Hashes for pylibjpeg_rle-1.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bef21bb61e3412d36c4b74d7c3679143876e18bc2c2583b3501e80d82aa2ce3 |
|
MD5 | e5f6a6bad6a2c66eddf72737345df335 |
|
BLAKE2b-256 | d30516b5ad00fd120489d4bff459f17466ada46daed979831ff69af7f19165e9 |
Hashes for pylibjpeg_rle-1.2.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e6a2f1ebd830f4bcaadc88c4c088329c4af26397f3c357aee0d3f7079c7d72d |
|
MD5 | cbc134244ae9b9200ba82be3d2ebff69 |
|
BLAKE2b-256 | eecfec0bfaccf09bb3f59aae30778185d9b9169366cea9d60ca13b12531f3fa6 |
Hashes for pylibjpeg_rle-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca8998d159dcb8c74ae01113758e7712f2d41d2bee88e2e1a53802451bd7a50 |
|
MD5 | 8b6c842327637a9468b8ade6111adcc6 |
|
BLAKE2b-256 | 721d0918dbbc69a410046c2aab1a1b485c248e9e4d56cc35989c392b0966a0dc |
Hashes for pylibjpeg_rle-1.2.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cdf8fda4d4bc49f3a37cf96da3e078c3fc9dac0c0ccefcafc0805f5e3ca1224 |
|
MD5 | 6bdd706a846c082171e3dd2ec4a594a8 |
|
BLAKE2b-256 | 6dd2d2ef9e06924b926294a6143921cc92fd7f52e4c7f9406e78c05c24f69bb0 |
Hashes for pylibjpeg_rle-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4793c109b78f7450afd2136816bf7996d4a7214f50cbe43692c25c4b1eb3950 |
|
MD5 | 103970e46fc469fc9d9c6ec99b4c31a5 |
|
BLAKE2b-256 | 193c962a017b489fb5b73bfd58d5f26a56c164d7139cc8e384589de30364fb6a |