def generate_frames(ds): """Yield decompressed pixel data frames as :class:`numpy.ndarray`. .. deprecated:: 1.2 Use :func:`~pydicom.pixel_data_handlers.pylibjpeg_handler.generate_frames` instead Parameters ---------- ds : pydicom.dataset.Dataset The dataset containing the pixel data. Yields ------ numpy.ndarray A single frame of the decompressed pixel data. """ try: import pydicom except ImportError: raise RuntimeError("'generate_frames' requires the pydicom package") from pydicom.encaps import generate_pixel_data_frame from pydicom.pixel_data_handlers.util import pixel_dtype decoders = get_pixel_data_decoders() decode = decoders[ds.file_meta.TransferSyntaxUID] p_interp = ds.PhotometricInterpretation nr_frames = getattr(ds, 'NumberOfFrames', 1) for frame in generate_pixel_data_frame(ds.PixelData, nr_frames): arr = decode(frame, ds.group_dataset(0x0028)).view(pixel_dtype(ds)) yield reshape_frame(ds, arr)
HAVE_RLE = False from pydicom import config from pydicom.encaps import generate_pixel_data_frame from pydicom.pixel_data_handlers.util import (pixel_dtype, get_expected_length, reshape_pixel_array, get_j2k_parameters) from pydicom.uid import (JPEGBaseline8Bit, JPEGExtended12Bit, JPEGLosslessP14, JPEGLosslessSV1, JPEGLSLossless, JPEGLSNearLossless, JPEG2000Lossless, JPEG2000, RLELossless, UID) LOGGER = logging.getLogger("pydicom") HANDLER_NAME = "pylibjpeg" if HAVE_PYLIBJPEG: _DECODERS = get_pixel_data_decoders() _LIBJPEG_SYNTAXES = [ JPEGBaseline8Bit, JPEGExtended12Bit, JPEGLosslessP14, JPEGLosslessSV1, JPEGLSLossless, JPEGLSNearLossless ] _OPENJPEG_SYNTAXES = [JPEG2000Lossless, JPEG2000] _RLE_SYNTAXES = [RLELossless] SUPPORTED_TRANSFER_SYNTAXES = (_LIBJPEG_SYNTAXES + _OPENJPEG_SYNTAXES + _RLE_SYNTAXES) DEPENDENCIES = {"numpy": ("http://www.numpy.org/", "NumPy")} def is_available() -> bool: """Return ``True`` if the handler has its dependencies met."""
import pytest try: import pydicom import pydicom.config HAS_PYDICOM = True except ImportError as exc: HAS_PYDICOM = False from pylibjpeg.data import get_indexed_datasets from pylibjpeg.pydicom.utils import get_j2k_parameters, generate_frames from pylibjpeg.utils import get_pixel_data_decoders decoders = get_pixel_data_decoders() HAS_PLUGINS = bool(decoders) HAS_JPEG_PLUGIN = '1.2.840.10008.1.2.4.50' in decoders HAS_JPEG_LS_PLUGIN = '1.2.840.10008.1.2.4.80' in decoders HAS_JPEG_2K_PLUGIN = '1.2.840.10008.1.2.4.90' in decoders RUN_JPEG = HAS_JPEG_PLUGIN and HAS_PYDICOM RUN_JPEGLS = HAS_JPEG_LS_PLUGIN and HAS_PYDICOM RUN_JPEG2K = HAS_JPEG_2K_PLUGIN and HAS_PYDICOM PY_VERSION = sys.version[:2] @pytest.mark.skipif(not HAS_PYDICOM or HAS_PLUGINS, reason="Plugins available") class TestNoPlugins: """Test interactions with no plugins."""