0

I am trying to follow the tutorial here:

http://www.rexcardan.com/2014/10/evil-dicom-basics/

and process my DICOM file to show the image. In the tutorial, the DICOMObject.Open() method is called to process the file path. My issue is that intellisense does not pick this up for me. Would anyone be able to assist with this?

I downloaded this version:

https://github.com/rexcardan/Evil-DICOM

EDIT

Using the following:

var dcm = DICOMObject.Read(@"C:\file\path\filename.dcm");

While stepping through the code of DICOMObject everything seems to be working fine up to this point:

public static IDICOMElement ReadElementImplicitLittleEndian(DICOMBinaryReader dr)
{
    var tag = TagReader.ReadLittleEndian(dr);
    var vr = TagDictionary.GetVRFromTag(tag);
    int length = LengthReader.ReadLittleEndian(VR.Null, dr);
    var data = DataReader.ReadLittleEndian(length, dr, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN);
    var el = ElementFactory.GenerateElement(tag, vr, data, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN);
    return el;
}

When the code gets to:

int length = LengthReader.ReadLittleEndian(VR.Null, dr);

length returns an int of 1919252000 bytes which is ~2GB. Then the code steps to:

var data = DataReader.ReadLittleEndian(length, dr, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN);

Which checks to see if there are any bytes to read (which there is) and goes to the read bytes here:

public byte[] ReadBytes(int count)
{
    byte[] buffer = new byte[count];
    _binaryReader.Read(buffer, 0, count);
    return buffer;
}

byte[] buffer = new byte[count]; is where the actual exception occurs in the code. I have tested the amount of bytes that it can handle and it seems to be around .6 - .7 GB which is not even half of what I need. Is there away to expand the buffer to accept all of what I need?

Cœur
  • 37,241
  • 25
  • 195
  • 267
scapegoat17
  • 5,509
  • 14
  • 55
  • 90
  • The `OutOfMemoryException` arises for very large DICOM files, more than 0.6 GB, you mean? And reading works for smaller files? – Anders Gustafsson Jan 15 '15 at 17:17
  • @AndersGustafsson - That is correct. If I shorten the length parameter to return with less than 0.6 GB worth of bytes in the byte[] it seems to proceed and create the rest of the file. – scapegoat17 Jan 15 '15 at 18:16
  • Sounds like some code improvements would be required. I recommend that you post an issue on the Evil DICOM Github site. – Anders Gustafsson Jan 15 '15 at 18:51
  • @AndersGustafsson - Okay, not to familiar with Github. where do I go to post issues? – scapegoat17 Jan 15 '15 at 18:56
  • Issues tab is [here](https://github.com/rexcardan/Evil-DICOM/issues). You would also need to sign up for Github, if you haven't already. – Anders Gustafsson Jan 15 '15 at 19:31
  • 1
    @AndersGustafsson - Thank you for the help. I opened an issue. I will mark you answer as correct since you technically did resolve my original issue. Thank you for all the information and help! – scapegoat17 Jan 15 '15 at 23:33

3 Answers3

1

I have not looked at the video, but as far as I know you should use:

var dicomObj = DICOMObject.Read(filePath);

to read a DICOM file using Evil DICOM.

Please see the source code here. I am not sure, but there may have been a recent API change that explains this confusion.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • After doing more research last night, I came to the same conclusion. However, I seem to be getting an annoying error using your code: `Exception of type 'System.OutOfMemoryException' was thrown.`. Have you ever come across this using the `DICOMObject.Read()`? – scapegoat17 Jan 15 '15 at 13:38
  • @scapegoat17 I assume you are getting this error with Rex's library, right? (I manage a Portable Class Library fork of Evil DICOM, that is why I am asking.) I suggest you post an issue on Rex's Github site, and include a more detailed stack trace of the exception and, if possible the DICOM file that causes the failure. – Anders Gustafsson Jan 15 '15 at 14:00
  • You are correct. It is in Rex's library. I would like for you to see my edit above and if you do not see anything that jumps out at you I will post what I found into the Github site. – scapegoat17 Jan 15 '15 at 16:10
0

Sorry for the late response.

My first thought is that the file is not actually encoded in Implicit VR Little Endian. This is the default transfer syntax that is presumed if the DICOM preamble and metadata are missing. Normally, in the metadata (Tags starting with 0002), the transfer syntax is revealed. On the actual file (in Windows explorer, not from ED), is the size really 600+MB? If so, what kind of file is that so I can play with one?

I added a new method to the DICOMObject class that let's you try another syntax on a read fail:

    /// <summary>
    ///     Reads a DICOM file from a path
    /// </summary>
    /// <param name="filePath">the path to the file</param>
    /// <param name="trySyntax">the transfer syntax to use in case there is no metadata explicitly included</param>
    /// <returns></returns>
    public static DICOMObject Read(string filePath,
        TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
    {
        return DICOMFileReader.Read(filePath, trySyntax);
    }

I've run across some badly formatted DICOM in my experiences that have caused me errors like the one you are mentioning. Of course, it could really be that you are running out of memory, which I would like to dive into further if you are sure the transfer syntax is correct. Try "Explicit VR Little Endian" and see if that fixes your problem.

RexCardan
  • 398
  • 2
  • 7
0

Try this

var bdcm= File.ReadAllBytes(@"AbsolutePath");
var dcm = DICOMObject.Read(bdcm);
Abhii
  • 295
  • 2
  • 6
  • 18