Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RLE encoding functions * Add test coverage * Add benchmarks for encoding
- Loading branch information
1 parent
ac93b4e
commit 3155288
Showing
4 changed files
with
891 additions
and
69 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
pydicom/benchmarks/bench_handler_rle.py → ...om/benchmarks/bench_handler_rle_decode.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2008-2018 pydicom authors. See LICENSE file for details. | ||
"""Encoding benchmarks for the rle_handler module.""" | ||
|
||
import numpy as np | ||
|
||
from pydicom import dcmread | ||
from pydicom.data import get_testdata_files | ||
from pydicom.pixel_data_handlers.rle_handler import ( | ||
rle_encode_frame, | ||
_rle_encode_segment, | ||
) | ||
|
||
# 8/8-bit, 1 sample/pixel, 1 frame | ||
EXPL_8_1_1F = get_testdata_files("OBXXXX1A.dcm")[0] | ||
# 8/8-bit, 3 sample/pixel, 1 frame | ||
EXPL_8_3_1F = get_testdata_files("SC_rgb.dcm")[0] | ||
# 16/16-bit, 1 sample/pixel, 1 frame | ||
EXPL_16_1_1F = get_testdata_files("MR_small.dcm")[0] | ||
# 16/16-bit, 3 sample/pixel, 1 frame | ||
EXPL_16_3_1F = get_testdata_files("SC_rgb_16bit.dcm")[0] | ||
# 32/32-bit, 1 sample/pixel, 1 frame | ||
EXPL_32_1_1F = get_testdata_files("rtdose_1frame.dcm")[0] | ||
# 32/32-bit, 3 sample/pixel, 1 frame | ||
EXPL_32_3_1F = get_testdata_files("SC_rgb_32bit.dcm")[0] | ||
|
||
|
||
class TimeRLEEncodeSegment(object): | ||
"""Time tests for rle_handler._rle_encode_segment.""" | ||
def setup(self): | ||
ds = dcmread(EXPL_8_1_1F) | ||
self.arr = ds.pixel_array | ||
|
||
self.no_runs = 100 | ||
|
||
def time_encode(self): | ||
"""Time encoding a full segment.""" | ||
# Re-encode the decoded data | ||
for ii in range(self.no_runs): | ||
_rle_encode_segment(self.arr) | ||
|
||
|
||
class TimeRLEEncodeFrame(object): | ||
"""Time tests for rle_handler.rle_encode_frame.""" | ||
def setup(self): | ||
ds = dcmread(EXPL_8_1_1F) | ||
self.arr8_1 = ds.pixel_array | ||
ds = dcmread(EXPL_8_3_1F) | ||
self.arr8_3 = ds.pixel_array | ||
ds = dcmread(EXPL_16_1_1F) | ||
self.arr16_1 = ds.pixel_array | ||
ds = dcmread(EXPL_16_3_1F) | ||
self.arr16_3 = ds.pixel_array | ||
ds = dcmread(EXPL_32_1_1F) | ||
self.arr32_1 = ds.pixel_array | ||
ds = dcmread(EXPL_32_3_1F) | ||
self.arr32_3 = ds.pixel_array | ||
|
||
self.no_runs = 100 | ||
|
||
def time_08_1(self): | ||
"""Time encoding 8 bit 1 sample/pixel.""" | ||
for ii in range(self.no_runs): | ||
rle_encode_frame(self.arr8_1) | ||
|
||
def time_08_3(self): | ||
"""Time encoding 8 bit 3 sample/pixel.""" | ||
for ii in range(self.no_runs): | ||
rle_encode_frame(self.arr8_3) | ||
|
||
def time_16_1(self): | ||
"""Time encoding 16 bit 1 sample/pixel.""" | ||
for ii in range(self.no_runs): | ||
rle_encode_frame(self.arr16_1) | ||
|
||
def time_16_3(self): | ||
"""Time encoding 16 bit 3 sample/pixel.""" | ||
for ii in range(self.no_runs): | ||
rle_encode_frame(self.arr16_3) | ||
|
||
def time_32_1(self): | ||
"""Time encoding 32 bit 1 sample/pixel.""" | ||
for ii in range(self.no_runs): | ||
rle_encode_frame(self.arr32_1) | ||
|
||
def time_32_3(self): | ||
"""Time encoding 32 bit 3 sample/pixel.""" | ||
for ii in range(self.no_runs): | ||
rle_encode_frame(self.arr32_3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.