LAUREL BRIDGE

LaurelBridge.DCFExamples.Transcode Namespace

DICOM Connectivity Framework V3.4
The Transcode example demonstrates how to use the DCF to change the transfer syntax of a DICOM dataset.
Classes

  ClassDescription
Public classOptions
Command line options class for parsing user options for Transcode.
Public classProgram
This example demonstrates how to use the DCF library to convert datasets to change the transfer syntax of the encoded pixel data, also known as transcoding.
Remarks

Supported OS Platforms:

  • Windows - .Net Framework 4.7.2 64-bit and 32-bit
  • Windows - .Net Core 2.1 64-bit and 32-bit
  • Linux - .Net Core 2.1 64-bit

Examples

Transcode Sample Code
/// <summary>
/// Main entry point for DatasetDump. See the <see cref="Options"/> class for usage and options.
/// </summary>
/// <param name="args">command line arguments</param>
public static void Main(string[] args)
{
    Console.WriteLine("DCF Library using target framework {0}", DCFVersion.TargetFramework);
    try
    {
        Options options;
        if (!Options.TryParse(args, out options))
        {
            throw new ArgumentException("bad command line parameters");
        }

        // see if user overrides in configuration file format
        if (!string.IsNullOrEmpty(options.CfgOverrides))
        {
            // LoadConfiguration prepends Framework.ConfigurationPath for relative paths
            Framework.LoadConfiguration(Path.GetFullPath(options.CfgOverrides));
        }

        DicomSessionSettings ss = ConfigureSession(options);

        // Convert symbolic name to a uid if necessary
        string transferSyntaxUid = ToTransferSyntaxUid(options.TransferSyntax);
        if (transferSyntaxUid == null)
        {
            throw new InvalidOperationException("unrecognized transfer syntax");
        }

        string inputPath = options.Input;
        if (!File.Exists(inputPath))
        {
            throw new FileNotFoundException(inputPath);
        }

        string outputPath = options.Output;

        Stopwatch sw = Stopwatch.StartNew();
        using (DicomFileInput dfi = new DicomFileInput(inputPath, ss))
        {
            DicomDataSet dds = dfi.ReadDataSet();
            using (DicomFileOutput dfo = new DicomFileOutput(outputPath, transferSyntaxUid, ss))
            {
                dfo.WriteDataSet(dds);
            }
        }
        sw.Stop();
        long elapsed = sw.ElapsedMilliseconds;

        Console.WriteLine("input={0} => output={1}, tsuid={2}, elapsed={3}ms",
            inputPath, outputPath, transferSyntaxUid, elapsed);

        if (options.DumpStats)
        {
            DumpStats(options.Input, options.Output, sw.ElapsedMilliseconds);
        }

    }
    catch (Exception e)
    {
        Console.WriteLine("Exception caught during execution: {0}", e);
        Environment.ExitCode = 1;
    }
    finally
    {
        if (Debugger.IsAttached)
        {
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey();
        }
    }
}