Skip to content

Commit

Permalink
successfully compress dicom pixel data
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Aug 29, 2024
1 parent d4d5956 commit 9bae269
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions dicommake.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pydicom.uid import ExplicitVRLittleEndian,JPEG2000, JPEG2000Lossless
import pylibjpeg
from pydicom.uid import RLELossless
from pydicom.encaps import encapsulate
LOG = logger.debug
logger_format = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> │ "
Expand Down Expand Up @@ -81,6 +82,11 @@
dest = 'thread',
action = 'store_true',
default = False)
parser.add_argument("--compress",
help = "if specified, compress the DICOM pixel data",
dest = 'compress',
action = 'store_true',
default = False)
parser.add_argument('--version',
action = 'version',
version = f'%(prog)s {__version__}')
Expand Down Expand Up @@ -147,23 +153,18 @@ def npimage_get(image):
# The below fix handles this.
# We change the transfer syntax UID (https://github.com/pydicom/pydicom/issues/1109)
ds.PixelData = np_image.tobytes()
ds.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian


ds.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
ds.AcquisitionTime = AcquisitionTime()
ds.AcquisitionDate = AcquisitionDate()
ds.SeriesInstanceUID = pydicom.uid.generate_uid()
ds.SOPInstanceUID = pydicom.uid.generate_uid()

# NB! If this is not set, images will not render properly in Cornerstone
ds.PlanarConfiguration = 0
ds.compress(RLELossless)
# Recompress the image data using JPEG2000
# compressed_pixel_data = pylibjpeg.encode(np_image.tobytes(), transfer_syntax='JPEG2000')

# Update the DICOM dataset
# ds.PixelData = compressed_pixel_data
ds.file_meta.TransferSyntaxUID = JPEG2000
# Compress the pixel data
ds.compress(RLELossless)
ds.file_meta.TransferSyntaxUID = RLELossless
return ds

def doubly_map(x: PathMapper, y: PathMapper) -> Iterable[tuple[Path, Path, Path, Path]]:
Expand Down

0 comments on commit 9bae269

Please sign in to comment.