|
Medical Imaging in IDL: IDL DICOM Reference |
|
The IDLffDicomEx::ChangeTransferSyntax procedure method changes the transfer syntax of the IDLffDicomEx object and its associated pixel data. This allows you to change the compression setting of the pixel data and ensure that the transfer syntax value and pixel data are synchronized. Directly changing the transfer syntax (0002,0010) is not advised.
| Note There is no support for the JPEG compression algorithms on Macintosh. See File Compression and Transfer Syntax Support for information on supported transfer syntaxes |
| Note Attempting to change an existing file from a lossy JPEG format to another format will fail. This is prohibited to ensure that a file saved in a lossy format is always known to be less than the original data. |
| Note When this method successfully completes the equivalent of an IDLffDicomEx::Commit call will have occurred (the file is saved to disk) to ensure the pixel data and the transfer syntax are synchronized. This means any sequence identifiers for the object are invalid and must be re-accessed using the IDLffDicomEx::GetPrivateValue or IDLffDicomEx::GetValue method. |
There are five scenarios in which this method may be used. The following lists the actions of the ChangeTransferSyntax method in each case:
The following table provides information on the types of JPEG compression support for images with various bit depths. Not all JPEG formats can be used on all image types. Refer to Digital Imaging and Communications in Medicine (DICOM) - Part 5: Data Structures and Encoding for additional details.
Obj->[IDLffDicomEx::]ChangeTransferSyntax, NewSyntaxUID [, /LOSSY]
A string that specifies the new transfer syntax for the file. This argument must be one of the values listed in the following table:
Set this keyword to control how tags that can indicate lossy compression are updated. The default behavior when the NewSyntaxUID argument is set to a lossy transfer syntax is to update the two tags as indicated in the following table. This occurs when the LOSSY keyword is not set. If this keyword is set the indicated tags remain unchanged. See Digital Imaging and Communications in Medicine (DICOM) - Part 3, Section C.7.6.1.1.5 for additional details on what other tags you can update when the compression format is lossy.
The following example changes the file compression of a selected file to a lossy format. Use the BITS_STORED property to query the bit depth of the image as not all images support all types of compression. Do not set the LOSSY keyword so the Image Type attribute is modified to state that the image is derived. Following compression, the original and compressed images are shown in a window.
| Note This example is not designed for images with more than a single sample per pixel (e.g. RGB images). |
| Note To avoid an error, you must delete the aImgClone.dcm file prior to running this example more than a single time. The ChangeTransferSyntax method internally calls the IDLffDicomEx::Commit method and writes the file to disk. |
PRO dicom_changecompression_doc
; Select a DICOM file.
sFile = DIALOG_PICKFILE( $
PATH=FILEPATH('',SUBDIRECTORY=['examples','data']), $
TITLE='Select DICOM Patient File', FILTER='*.dcm', $
GET_PATH=path)
; Create a clone (aImgClone.dcm) of the selected file (sfile).
; Set the NON_CONFORMING keyword to be able to add a public SQ
; of radiopharmaceutical items to any file.
oImg = OBJ_NEW('IDLffDicomEx', path + 'aImgClone.dcm', $
CLONE=sfile, /NON_CONFORMING)
; Get the value of the Image Type attribute prior to
; changing the transfer syntax.
oImg->GetProperty, IMAGE_TYPE = vImgType, $
ROWS=vRows, COLUMNS=vCols
PRINT, 'Image Type Property = ', vImgType
; Check to see if the image has multiple frames.
frameTest = oImg->QueryValue('0028,0008')
IF FrameTest EQ 2 THEN BEGIN
oImg->GetProperty, NUMBER_OF_FRAMES=frame
frame = frame - 1
ENDIF ELSE BEGIN
frame = 0
ENDELSE
order = 0
; Get the current transfer syntax.
oImg->GetProperty, TRANSFER_SYNTAX = vSyntax, $
BITS_STORED = vBits
PRINT, 'Old Syntax ', vSyntax
; Get the pixel data before compression.
vPixOrig = oImg->GetPixelData(ORDER=vOrder, COUNT=vCnt)
; Change the compression of the file to a lossy type based on
; bit-depth of the image. Note that internally, the
; ChangeTransferSyntax calls commit and writes file to disk.
If vBits EQ 8 THEN $
oImg->ChangeTransferSyntax, '1.2.840.10008.1.2.4.50'
IF vBits NE 8 THEN BEGIN
; If vBits not equal to 8 then compress the file using
; JPEG 2000 lossy compression.
oImg->ChangeTransferSyntax, '1.2.840.10008.1.2.4.91'
ENDIF
oImg->GetProperty, TRANSFER_SYNTAX = vSyntax, $
IMAGE_TYPE = vImgType
PRINT, 'New Syntax ', vSyntax
PRINT, 'New Image Type Property = ', vImgType
; Retrieve the compress pixel data.
vPixLossy = oImg->GetPixelData()
; Display the original and lossy compressed data.
WINDOW, XSIZE = vCols*2, YSIZE = vRows, $
TITLE = "Original and Compressed Frames"
FOR i = 1, frame+1 DO BEGIN
TVSCL, vPixOrig[*,*,i-1], 0, ORDER = order
TVSCL, vPixLossy[*,*,i-1], 1, ORDER = order
WAIT, 1
ENDFOR
; Clean up references.
OBJ_DESTROY, oImg
END
IDL Online Help (March 06, 2007)