LAUREL BRIDGE

LaurelBridge.DCF.Examples.CreateBasicOffsetTable Namespace

DICOM Connectivity Framework V3.4
The CreateBasicOffsetTable demonstrates how to use DCF to create basic frame tables for multiframe image datasets.
Classes

  ClassDescription
Public classOptions
Command line options class for parsing user options for CreateBasicOffsetTable.
Public classProgram
DICOM defines the notion of a basic offset table for encapsulated pixel data elements to aid in finding the start of each image frame in a multiframe image. The basic offset table is the first sequence fragment after the pixel data element header, and it is allowed to be empty, or to have a sequence of 32-bit unsigned offset values that indicate the starting offset of each frame in the compressed datastream. Each frame offset is relative to the end of the basic offset table, so the first offset is always zero.

While the basic offset table is useful for readers, it is not required, since readers are required to be able to handle empty basic offset tables. For writers, the creation of the basic offset table can be inefficient since the size of the compressed image fragments that follow is not known in advance, so unless the output that the writer is writing to is seekable, the entire compressed image stream must be buffered in order to write the basic offset table first.

Examples

CreateBasicOffsetTable Sample Code
public class Program
{
    private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

    /// <summary>
    /// Main entry point for CreateBasicOffsetTable.
    /// </summary>
    /// <param name="args">command line arguments</param>
    [STAThread]
    public static void Main(string[] args)
    {
        try
        {
            Options options;
            if (!Options.TryParse(args, out options))
                return;

            // use the frame producer to see if inputPath has usable frame offsets
            using (FrameProducer fp = FrameProducer.CreateFromFile(options.InputPath))
            {
                fp.GetFrameOffsets(); // loads basic offset table if available, or creates if not available
                Logger.InfoFormat("Path({0}), WasOffsetTableValid({1}){2}{3}",
                    options.InputPath, fp.WasOffsetTableValid, Environment.NewLine, fp.DumpFrameOffsets());
            }

            using (DicomFileInput dfi = new DicomFileInput(options.InputPath))
            {
                DicomDataSet inputDataSet = dfi.ReadDataSet();
                string tsUid = String.IsNullOrEmpty(options.TransferSyntax) ? dfi.ActualTsUid : options.TransferSyntax;
                DicomSessionSettings sessionSettings = new DicomSessionSettings() { BasicOffsetTableCreationMode = options.CreationMode };
                using (DicomFileOutput dfo = new DicomFileOutput(options.OutputPath, tsUid, sessionSettings))
                {
                    dfo.WriteDataSet(inputDataSet);
                }
            }

            // use the frame producer to see if inputPath has usable frame offsets
            using (FrameProducer fp = FrameProducer.CreateFromFile(options.OutputPath))
            {
                fp.GetFrameOffsets(); // loads basic offset table if available, or creates if not available
                Logger.InfoFormat("Path({0}), WasOffsetTableValid({1}){2}{3}",
                    options.OutputPath, fp.WasOffsetTableValid, Environment.NewLine, fp.DumpFrameOffsets());
            }
        }
        catch (Exception e)
        {
            Logger.ErrorFormat("error during execution: {0}", e);
        }
        finally
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey();
            }
        }
    }
}