Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Sunday, September 12, 2004 9:34:33 PM(UTC)

hlo  
hlo

Groups: Registered
Posts: 2


Hi,

Another hard-time in using LeadDicomDs class...  I have been trying to compress dicom image using various JPEG and J2K compression level but nothing seems to work. The file size is still the same. The only changes that I can see is the photometric level.

Below is a portion of code assuming gLeadDicomDs has successfully load the image.

newDicomDS.ResetDS()

newDicomDS.hDicomDS = gLeadDicomDS.hDicomDS

'move to Image Pixel Data element

gLeadDicomDS.FindFirstElement(DicomDataSetTagConstants9.TAG_PIXEL_DATA, False)

gLeadDicomDS.GetBitmapValue(0, 0, Me.colororder, loadbmpcons)

newDicomDS.Bitmap = gLeadDicomDS.Bitmap

'set J2K compression level

gLeadDicomDS.J2KOptions.J2KCompressionControl = DicomJ2KCompressionControl.DICOM_J2K_COMP_QFACTOR

gLeadDicomDS.J2KOptions.J2KCompressionRatio = 50.0

nret = newDicomDS.SetBitmapValue(Me.complevel, Me.photometriclevel, 0, 100, 0)

If nret <> DicomErrorCodes.DICOM_SUCCESS Then

MessageBox.Show("Error " & CStr(nret) & " set bitmap value!")

'Exit Sub

End If

nret = newDicomDS.SaveDS("c:\newdicom.dcm", 0)

If nret <> DicomErrorCodes.DICOM_SUCCESS Then

MessageBox.Show("Error " & CStr(nret) & " saving file!")

'Exit Sub

End If

I have tried heaps of combination of variables, but nothing can really show the significant changes except the photometric level. If you could show me a simple example in using one of the compression e.g. JPEG compression, thats really appreciated.

Also, if the compression really works, does it update the transfer syntax UID (0002, 0010) as well? e.g. JPEG Lossless compression shall be 1.2.840.10008.1.2.4.57. If not, is there a way to know what compression level had been applied to particular dicom file?

Looking forward for the reply soon.

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, May 6, 2005 12:56:02 PM(UTC)

Diya  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

First of all Dicom dataset needs to be in DS_EXPLICIT_VR and DS_LITTLE_ENDIAN transfer syntax to insert compressed image unless file already has compressed transfer syntax and you are adding more frames to it with same compression. Also, you cannot insert a frame in to an existing DICOM with different compression than the one already in the file.

In order to compress the image in the existing DICOM dataset, you need to extract the images out of DICOM dataset and delete the Pixel Data element and save it to a temporary file with DS_EXPLICIT_VR|DS_LITTLE_ENDIAN flags. Than free the DS and reload the temporary DIUCOM file and insert the pixel data element and images to it with any LEADTOOLS supported DICOM compression. Now you can save the DICOM Dataset with SaveDS call and DO NOT pass any flags that will modify the transfer syntax of the image (i.e. DS_IMPLICIT_VR or DS_EXPLICIT_VR or DS_LITTLE_ENDIAN or DS_BIG_ENDIAN or DS_LENGTH_EXPLICIT).

ChangeTransferSyntax method is your best option for converting compression in existing image in DICOM dataset. If you are initializing the dataset and creating a new DICOM file always use DS_EXPLICIT_VR |DS_LITTLE_ENDIAN|DS flags in calls to InitDS method. If a DICOM dataset with image already exist and you want to change the transfer syntax or compression, you can also follow the following steps instead of calling ChangeTransferSyntax:

We added a new flag called "DS_KEEP_PIXEL_DATA_INTACT (0x0400)&#8221;, please make sure that you pass this flag whenever you call "LoadDS" or "InitDS&#8221;.
Whenever this flag is set, LEADTOOLS will not modify the image data when you retrieve the image. If the flag is not set we may convert the image to unsigned and monochrome 1 to monochrome 2 format.
In order to insert the image back into a dataset and have it display properly by third party applications please follow the steps below:

Start by loading thedataset by callingLoadDS and passing DS_KEEP_PIXEL_DATA_INTACTflag.
Now extract the values for the following elements (if available in the dataset):
  • Smallest Image Pixel Value (0028,0106)
  • Largest Image Pixel Value (0028,0107)
  • Window Center (0028,1050), value multiplicity could be more than 1.
  • Window Width (0028,1051), value multiplicity could be more than 1.
  • Rescale Slope (0028,1052)
  • Rescale Intercept (0028,1053)
  • Bit Allocated
  • Bit Stored (0028,0101)
  • High Bit (0028,0102)
  • Pixel Representation (0028,0103)
  • Photometric Interpretation


Extract the image(s).



If the dataset has




A compressed transfer syntax such as
1. 1.2.840.10008.1.2.4.50.
2. 1.2.840.10008.1.2.4.51.
3. 1.2.840.10008.1.2.4.70.
4. 1.2.840.10008.1.2.5.
5. 1.2.840.10008.1.2.4.57

Then delete the pixel data element and also update the transfer syntax element with Explicit VR Little Endian.
An"Explicit VR Little Endian" transfer syntax then just delete the pixel data element.

Other transfer syntaxes (Implicit VR little Endian , Explicit VR big endian) then delete the pixel data element and save the dataset by calling SaveDS to a temp file and pass DS_EXPLICIT_VR |DS_LITTLE_ENDIAN|DS_METAHEADER_PRESENT then call ResetDS andcall LoadDSto load the temp file.
6. Insert the pixel data element (VR_OW)
7. Insert the image(s) with desired compression or uncompressed.
Note: you cannot insert 16-bit lossy JPEG. Not a valid option for DICOM.
8. Restore the following elements with saved value from above:
  • Smallest Image Pixel Value (0028,0106)
  • Largest Image Pixel Value (0028,0107)
  • Window Center (0028,1050), value multiplicity could be more than 1.
  • Window Width (0028,1051), value multiplicity could be more than 1.
  • Rescale Slope (0028,1052)
  • Rescale Intercept (0028,1053)
  • Bit Allocated
  • Bit Stored (0028,0101)
  • High Bit (0028,0102)
  • Pixel Representation (0028,0103)
  • Photometric Interpretation

Note: If the original Dataset didn't have "Smallest Image PixeValue " and "Largest Image Pixel Value " elements then make sure that you delete them from the current dataset.
9. Call SaveDS to save the dataset with only these flags: DS_METAHEADER_PRESENT.

In your sample code, you are setting J2K compression for gLeadDicomDS and inserting the image in newDicomDS. Yes, we update the transfer syntax element to reflect the compression used in the dataset. Our default JPEG Lossless compression transfer syntax is 1.2.840.10008.1.2.4.70 but we save the file in a way so that changing the value for transfer syntax to 1.2.840.10008.1.2.4.57 will also work.

I would use the change transfer syntax function (COM : ChangeTransferSyntax method (ILEADDicomDS), C++: LDicomDS::ChangeTransferSyntax, API: L_DicomChangeTransferSyntax) , it should take care of all the details above and much more, you can use it regardless what your source and destination transfer syntax is.

Edited by moderator Wednesday, April 5, 2017 8:01:40 AM(UTC)  | Reason: Not specified

 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.129 seconds.