Skip to content

Commit 5a2b38f

Browse files
committed
upate decoder
Signed-off-by: M Q <mingmelvinq@nvidia.com>
1 parent b7d58ef commit 5a2b38f

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

monai/deploy/operators/decoder_nvimgcodec.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def _decode_frame(src: bytes, runner: DecodeRunner) -> bytearray | bytes
5959

6060
import inspect
6161
import logging
62-
import numpy as np
6362
import sys
6463
from pathlib import Path
6564
from typing import Any, Callable, Iterable
6665

66+
import numpy as np
6767
from pydicom.pixels.decoders import (
6868
HTJ2KDecoder,
6969
HTJ2KLosslessDecoder,
@@ -190,47 +190,16 @@ def _decode_frame(src: bytes, runner: DecodeRunner) -> bytearray | bytes:
190190
if not is_available(tsyntax):
191191
raise ValueError(f"Transfer syntax {tsyntax} not supported; see details in the debug log.")
192192

193-
# Source image frame attributes
194-
rows = getattr(runner, 'rows', None)
195-
columns = getattr(runner, 'columns', None)
196-
samples_per_pixel = getattr(runner, 'samples_per_pixel', None)
197-
198-
199-
_logger.info("Source image frame attributes from DecodeRunner:")
200-
_logger.info(f"rows: {rows}")
201-
_logger.info(f"columns: {columns}")
202-
_logger.info(f"samples_per_pixel: {samples_per_pixel}")
203-
_logger.info(f"number_of_frames: {getattr(runner, 'number_of_frames', None)}") # Multi frame image, but one frame at a time
204-
_logger.info(f"index: {getattr(runner, 'index', None)}") # Current frame index in the image
205-
_logger.info(f"frame_length: {runner.frame_length()}") # Multi frame image, but one frame at a time
206-
_logger.info(f"extended_offsets: {getattr(runner, 'extended_offsets', None)}") # Multi frame image, but one frame at a time
207-
_logger.info(f"pixel_representation: {getattr(runner, 'pixel_representation', None)}")
208-
_logger.info(f"bits_allocated: {getattr(runner, 'bits_allocated', None)}")
209-
_logger.info(f"bits_stored: {getattr(runner, 'bits_stored', None)}")
210-
_logger.info(f"photometric_interpretation: {getattr(runner, 'photometric_interpretation', None)}")
211-
_logger.info(f"pixel_representation: {getattr(runner, 'pixel_representation', None)}")
212-
_logger.info(f"planar_configuration: {getattr(runner, 'planar_configuration', None)}")
213-
214-
215193
nvimgcodec_decoder = nvimgcodec.Decoder()
216194
decode_params = nvimgcodec.DecodeParams(allow_any_depth=True, color_spec=nvimgcodec.ColorSpec.UNCHANGED)
217-
decoded_data = nvimgcodec_decoder.decode(src, params=decode_params) # HWC layout, interleaved format, and contiguous array in C-style
218-
219-
_logger.info("Decoded data attributes:")
220-
_logger.info(f"decoded_data shape: {decoded_data.shape}")
221-
_logger.info(f"decoded_data dtype: {decoded_data.dtype}")
222-
_logger.info(f"decoded_data strides: {decoded_data.strides}")
223-
_logger.info(f"decoded_data width: {decoded_data.width}")
224-
_logger.info(f"decoded_data height: {decoded_data.height}")
225-
_logger.info(f"decoded_data ndim: {decoded_data.ndim}")
226-
_logger.info(f"decoded_data precision: {decoded_data.precision}")
227-
_logger.info(f"decoded_data buffer_kind: {decoded_data.buffer_kind}")
228-
229-
_logger.info("Decoded data copied to system memory:")
195+
decoded_data = nvimgcodec_decoder.decode(
196+
src, params=decode_params
197+
) # HWC layout, interleaved format, and contiguous array in C-style
230198
superface = np.asarray(decoded_data.cpu())
231199
np.ascontiguousarray(superface)
232200
return superface.tobytes()
233201

202+
234203
def _is_nvimgcodec_available() -> bool:
235204
"""Return ``True`` if nvimgcodec is available, ``False`` otherwise."""
236205

@@ -246,6 +215,7 @@ def _is_nvimgcodec_available() -> bool:
246215

247216
# Helper functions for an application to register this decoder plugin with Pydicom at application startup.
248217

218+
249219
def register_as_decoder_plugin(module_path: str | None = None) -> bool:
250220
"""Register as a preferred decoder plugin with supported decoder classes.
251221

0 commit comments

Comments
 (0)