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 : Monday, April 30, 2012 4:19:18 AM(UTC)

brass9  
brass9

Groups: Registered
Posts: 2


Hello:

I'm using the .Net DICOM SDK v17.

I'm trying to extract pixel data elements from DICOM objects and save it as a Jpeg 200 compressed image file.

I'm using the Save() method of the RasterCodecs (or the Jpeg2000Engine) class.

Here's the snippet of code:
var _pixelDataElement = _dcmDataset.FindFirstElement(null, DicomTag.PixelData, true);
var imageData = _dcmDataset.GetImage(pixelDataElement, 0, 0,
RasterByteOrder.Gray,
DicomGetImageFlags.AllowRangeExpansion |
DicomGetImageFlags.AutoApplyModalityLut |
DicomGetImageFlags.AutoApplyVoiLut);

_rasterCodecs.Save(imageData, outFile, RasterImageFormat.J2k, _bitsPerPixel);

// Or...
//_jpeg2KEngine.Save(_rasterCodecs, outFile, imageData, Jpeg2000FileFormat.LeadJp2, _bitsPerPixel, 14);

The above code works flawlessly.

However, if the source DICOM dataset contains lossy compressed (JPG/J2k) data, then the above code poses a problem - the resulting image file will be "double compressed", resulting in considerable loss of details.

So, my question is this: how to extract lossy J2k/JPEG compressed image from DICOM objects and save it to a j2k file without any further compression.

C/C++/C# code sample is welcome.

Thanks and regards.

- brass
 

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 : Monday, April 30, 2012 6:38:07 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

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

Brass,

Please try the following code:
+--------------+
DicomDataSet _dcmDataset = new DicomDataSet();
_dcmDataset.Load(@"c:\cannonRes.dcm", DicomDataSetLoadFlags.None);
        
DicomElement _pixelDataElement = _dcmDataset.FindFirstElement(null, DicomTag.PixelData, false);

DicomElement pixelDataChild = _dcmDataset.GetChildElement(_pixelDataElement, true);

pixelDataChild = _dcmDataset.GetNextElement(pixelDataChild, true, true);        

byte[] data = _dcmDataset.GetBinaryValue(pixelDataChild, (int)pixelDataChild.Length);

File.WriteAllBytes(@"c:\Res.j2k", data);
+--------------+

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Monday, April 30, 2012 8:07:15 AM(UTC)

brass9  
brass9

Groups: Registered
Posts: 2


Mehedi,

Thanks for the solution! It works! :)

One more question though.

I have to convert the raster image to unsigned before extracting pixel data:
+----------------------------------------------+
var command = new ConvertSignedToUnsignedCommand(ConvertSignedToUnsignedCommandType.ShiftNegativeToZero);
command.Run(_rasterImage);
+----------------------------------------------+
How does this part apply to the solution you had proposed?

Thanks again for the quick reply,
Invar Brass
 
#4 Posted : Tuesday, May 1, 2012 6:03:54 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

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

The code that I sent you gets the image data as binary data (header plus compressed pixels) and then saves it to a file on disk without decoding or modifying it.

If you want to perform any processing on the data, such as converting to unsigned, you will have to de-compress it first, which is the opposite of what you originally asked.

This means you will have to use GetImage(), then re-compress the image if you want to process it.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
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.079 seconds.