dicom / ruby-dicom

Library for reading, editing and writing DICOM files, as well as handling DICOM network communication. Written in the Ruby language.
http://dicom.rubyforge.org/
GNU General Public License v3.0
178 stars 67 forks source link

Unable to process RLE images #74

Open psarnow opened 6 years ago

psarnow commented 6 years ago

Trying to get the RLE images from a dicom export. Here is a sample .dcm that was sent through and saved via DServer. image_2814918156667436.dcm.zip

Can't figure out how to get anything but the thumbnail image (3x3 image grid). sample

Maybe this method needs to do something different?

Here is my dcm.summary System Properties: Ruby DICOM version: 0.9.8 Byte Order (CPU): Little Endian

DICOM Object Properties: Source: File (successfully read): tmp/image_2814918156667436.dcm Modality: Ultrasound Image Storage Meta Header: Yes Value Representation: Explicit Byte Order (File): Little Endian Pixel Data: Yes Image Size: 1024768 Number of frames: 1 Photometry: RGB Compression: RLE Lossless Bits per Pixel: 8 => ["Source: File (successfully read): tmp/image_2814918156667436.dcm", "Modality: Ultrasound Image Storage", "Meta Header: Yes", "Value Representation: Explicit", "Byte Order (File): Little Endian", "Pixel Data: Yes", "Image Size: 1024768", "Number of frames: 1", "Photometry: RGB", "Compression: RLE Lossless", "Bits per Pixel: 8"]

dicom commented 6 years ago

Thank you for reporting the issue.

I will investigate it and let you know of what I find out.

Best regards, Chris

On Fri, Sep 14, 2018 at 4:09 PM psarnow notifications@github.com wrote:

Trying to get the RLE images from a dicom export. Here is a sample .dcm that was sent through and saved via DServer. image_2814918156667436.dcm.zip https://github.com/dicom/ruby-dicom/files/2383602/image_2814918156667436.dcm.zip

Can't figure out how to get anything but the thumbnail image (3x3 image grid). [image: sample] https://user-images.githubusercontent.com/1322925/45555085-0dba8c00-b7f5-11e8-9042-033a7b49f38b.png

Maybe this method https://github.com/dicom/ruby-dicom/blob/master/lib/dicom/image_item.rb#L224 needs to do something different?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dicom/ruby-dicom/issues/74, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEKSDy8X51u6YtfGlRM6gz9Cb5JE07Fks5ua7ipgaJpZM4WpV_A .

psarnow commented 6 years ago

Great Chris. Really hoping we can get this to function properly. Please let me know if I can provide any more information.

dicom commented 6 years ago

Sorry for the somewhat late reply (I've been on a trip lately).

I have looked into it and indeed there seems to be something "funny" going on here. I'll investigate it further and hope to find a fix for it.

Best regards, Chris

dicom commented 6 years ago

Ok, so I've looked into this issue a little bit more.

The method which is at fault here is actually the decode_rle() method in image_item.rb: https://github.com/dicom/ruby-dicom/blob/master/lib/dicom/image_item.rb#L491

What separates your particular RLE file from the two samples I have already in the repository (and which decodes just fine), is that those images come up with one image segments in that method, where as your sample has 3 image segments.

There is probably a flaw in the way that method decodes the pixel data. However, it is not quite clear to me what exactly goes wrong. For some reason the image seems to be composed as 9 low-resolution "thumbnails", as opposed to one single high resolution image.

Unfortunately I didnt write that original RLE code and Im not really that familiar with. Furthermore I dont deal with RLE files in my work either, so Im somewhat unsure if I should spend the time to try to crack this one.

I found some resource on RLE decoding here: http://dicom.nema.org/DICOM/2013/output/chtml/part05/sect_G.3.html

There might be other better resources as well.

Let me know if you think you are able to have a go with this issue? If not I might try to ask in the ruby-dicom forum if anyone is willing and able to check it out.

Best regards, Chris