Skip to content

Instantly share code, notes, and snippets.

@rcd
Created November 2, 2010 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rcd/660248 to your computer and use it in GitHub Desktop.
Save rcd/660248 to your computer and use it in GitHub Desktop.
basic DICOM file operations
using Dicom;
using Dicom.Data;
namespace Dicom.Examples {
static void Main() {
Debug.InitializeConsoleDebugLogger();
// register compression codecs
DicomCodec.RegisterCodecs();
DicomCodec.RegisterExternalCodecs(".", "Dicom.Codec.*.dll");
// load DICOM tag dictionaries
if (File.Exists("dicom.dic"))
DcmDictionary.ImportDictionary("dicom.dic");
else
DcmDictionary.LoadInternalDictionary();
if (File.Exists("private.dic"))
DcmDictionary.ImportDictionary("private.dic");
// load DICOM file
DicomFileFormat ff = new DicomFileFormat();
ff.Load(@"test.dcm", DicomReadOptions.AllowSeekingForContext);
// print dataset to log
Debug.Log.Info(ff.Dataset.Dump());
// get study instance uid
string studyuid = ff.Dataset.GetString(DicomTags.StudyInstanceUID, null);
// print studyuid to log
Debug.Log.Info("Study UID: {0}", studyuid);
// set patient id
ff.Dataset.SetString(DicomTags.PatientID, "12345");
// lossless compress image
ff.ChangeTransferSytnax(DicomTransferSyntax.JPEGProcess14SV1, null);
// save DICOM file
ff.Save(@"out.dcm", DicomWriteOptions.Default);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment