Read dicom pixel data to create a matrix- using dcm4che3 in scala

277 views
Skip to first unread message

Karthik Vadla

unread,
Aug 15, 2016, 7:32:47 PM8/15/16
to dcm4che
Hello All, 

I'm trying to get the pixel data using dcm4che3 in scala. I want to create a matrix out of pixel data to do some transformations.


Before reading pixel data, i tried to get file metadata. I have End of file exception .
Can you please help me with this.

My code snippet in scala:
-----------------------------------

val dicomRdd = sparkContext.wholeTextFiles("dicomimages")
      val printbytes = dicomRdd.map { case (filepath, filedata) => filedata.getBytes().length }
      printbytes.foreach(println)

      val disRdd = dicomRdd.map { case (filepath, filedata) => new DicomInputStream(new ByteArrayInputStream(filedata.getBytes())) }

      val dm = disRdd.map {
        case dis =>
           val fmi = dis.getFileMetaInformation
           val data = dis.readDataset(-1, -1)
           data
      }

      dm.foreach(println)


Error:
--------

Job aborted due to stage failure: Task 0 in stage 1.0 failed 1 times, most recent failure: Lost task 0.0 in stage 1.0 (TID 1, localhost): java.io.EOFException
at org.dcm4che3.util.StreamUtils.readFully(StreamUtils.java:63)
at org.dcm4che3.io.DicomInputStream.readFully(DicomInputStream.java:383)
at org.dcm4che3.io.DicomInputStream.readValue(DicomInputStream.java:711)
at org.dcm4che3.io.DicomInputStream.readValue(DicomInputStream.java:536)


Please see attachment for complete error.



Thanks 
Karthik
eof_exception.txt

Karthik Vadla

unread,
Aug 24, 2016, 1:04:39 PM8/24/16
to dcm4che
I resolved above issue by creating dicominputstream using  file object instead of ByteArrayInputStream. 
But still i'm looking to create with ByteArrayInputStream.

Here i'm reading dicom files from hdfs. 

Thanks
Karthik
Reply all
Reply to author
Forward
0 new messages