storing DICOM object as byte[]

190 views
Skip to first unread message

norbi771

unread,
Feb 5, 2015, 12:50:39 PM2/5/15
to dcm...@googlegroups.com
Hi,

I am trying to save DICOM object directly to database instead of saving it to file.
Could you help me with this as I am getting some weird results.

Based on some code found in Weasis DICOM API in GetSCU I found the following code

    private void storeTo(Association as, Attributes fmi, PDVInputStream data, File file) throws IOException {
        LOG.info("{}: M-WRITE {}", as, file);
        file.getParentFile().mkdirs();
        DicomOutputStream out = new DicomOutputStream(file);
        try {
            out.writeFileMetaInformation(fmi);
            data.copyTo(out);
        } finally {
            SafeClose.close(out);
        }
    }

So I am trying to adjust it to my needs.
I can store byte[] to database so for tests I am temporaryly trying to get byte[] data from DICOM and save this data to file. 
When this is working fine I will further adjust function to work with DB

private void storeTo(Association as, Attributes fmi, PDVInputStream data, File file) throws IOException {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String transferSyntaxUID = fmi.getString(Tag.TransferSyntaxUID);
    String sOPInstanceUID = fmi.getString(Tag.MediaStorageSOPInstanceUID);
    data.copyTo(out);
    
    DicomOutputStream dos = new DicomOutputStream(new BufferedOutputStream(out), transferSyntaxUID);
//    DicomOutputStream dos = new DicomOutputStream(new BufferedOutputStream(out), UID.ExplicitVRLittleEndian);

    dos.writeFileMetaInformation(fmi);
    data.copyTo(dos);
    
        Path path = Paths.get("c:\\temp\\" + sOPInstanceUID + ".dcm");
        try {
          Files.write(path, out.toByteArray()); //creates, overwrites
        } catch (IOException ex) {
          System.out.println("exception");
        }

    SafeClose.close(dos);      
      
      
    }

If I run the above the received file is smaller then ones I get from the original function.
If I compare tags seen in Microdicom the resulting file doesn't have 0002* tags. 

And I am confused ....
Could you advice is that the proper way of saving dicom data to byte[] or should I do it in a different way

I will appreciate your comments.

Dimitri Pianeta

unread,
Feb 5, 2015, 4:29:26 PM2/5/15
to dcm...@googlegroups.com

I enclose a small program for change pixel data with helping dcm4che3.

ChangePixelData.java
Reply all
Reply to author
Forward
Message has been deleted
0 new messages