File size on disk - sensible way to output Images

As disk space usage has always been a priority when designing/implementing DICOM applications, "What is the best practice for writing DICOM files?" is becoming a very common question asked by our developers.

The idea here is to write uncompressed images in lossless-compressed format in order to reduce disk usage, and leave compressed images "as is".

So check against the "ReceivedSyntax" property of the input image (either read from disk or received over network), if it's one of those uncompressed formats then lossless compress it when you do "WriteFile"; and if the input image is already compressed then there is no need to save it in lossless format as this will require more disk space.

The following VB code shows how to write received images on to local disk:

 Private Sub  Viewer_ImageReceived(ByVal ReceivedImage As  DicomObjects.DicomImage, ByVal Association As Long,  
                                   isAdded As Boolean,Status As Long)

   If ReceivedImage.ReceivedSyntax = "1.2.840.10008.1.2" Or ReceivedImage.ReceivedSyntax = "1.2.840.10008.1.2.1" 
             Or ReceivedImage.ReceivedSyntax = "1.2.840.10008.1.2.2" Then
   ' if received as uncompressed, then losslessly compress it
       ReceivedImage.WriteFile filePath, True, "1.2.840.10008."
   Else otherwise save the image "As Is"
       ReceivedImage.WriteFile filepage, True, ReceivedImage.ReceivedSyntax
   End If

End Sub

Now we have another question here, what if input image is compressed and we want to make it even smaller when writing it out? In DicomObjects, you can actually use a different transfer syntax for "higher" compression, together with a "Quality Factor" to control how you want that image to be compressed. This happens transparently in DicomObjects, it reads in the compressed image, decompresses it and then re-compress it with higher compression and the quality factor the user provided.

Please note, if ReceivedSyntax is same as the transfer syntax for output, Quality Factor will be ignored and the output file size will be the same as the input file size. If you really wish to force a reduction in file size and quality, then use DecompressAll before writing the file using your new quality factor.