karthikvadla16
USA
1 Posts |
Posted - Aug 15 2016 : 18:48:18
|
Hi All,
I have a requirement to create a matrix for each .dcm image using pixel data. I tried below code using dcm4che in scala. I keep getting EOF exception when i specify ds.readDataset(-1,-1).
Can anyone help me with this. Really appreciate your help.
Code: ---------
import java.io.{ByteArrayInputStream} import org.dcm4che3.data.Tag import org.dcm4che3.imageio.plugins.dcm.{DicomMetaData} import org.dcm4che3.io.{BulkDataDescriptor, DicomInputStream} import org.dcm4che3.io.DicomInputStream.IncludeBulkData import org.scalatest.Matchers
class DicomTest extends TestingSparkContextWordSpec with Matchers {
"dicom folder" should { "contain 9 files" in {
//dicomimages folder is within spark-rk/core 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 => dis.setIncludeBulkData(IncludeBulkData.URI); dis.setBulkDataDescriptor(BulkDataDescriptor.PIXELDATA); dis.setURI("java:iis"); // avoid copy of pixeldata to temporary file val fmi = dis.readFileMetaInformation(); val ds = dis.readDataset(-1, -1); new DicomMetaData(fmi, ds) }
dm.map(m => m.getAttributes.getValue(Tag.PixelData)).foreach(println) } }
}
Error: (Please see attachment for complete error stack) ------------- Caused by: 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) at org.dcm4che3.io.DicomInputStream.readAttributes(DicomInputStream.java:497)
Karthik
Download Attachment: 2016815184739_eof_exception.txt |
|