示例#1
0
        public void WriteLittleEndian()
        {
            var dcm = DICOMFileReader.Read(Resources.explicitLittleEndian);

            //Writing a file out
            DICOMFileWriter.WriteLittleEndian("myPath.dcm", dcm);
        }
示例#2
0
        public void ReadImplicitLittleEndian()
        {
            var dcm       = DICOMFileReader.Read(Resources.implicitLittleEndian);
            var elemCount = dcm.AllElements.Count;

            Assert.AreEqual(elemCount, 47);
        }
示例#3
0
        public void ReadJPEG()
        {
            var dcm       = DICOMFileReader.Read(Resources.explicitLittleJPEG);
            var elemCount = dcm.AllElements.Count;

            Assert.AreEqual(elemCount, 80);
        }
示例#4
0
        public void ReadBigEndian()
        {
            var dcm       = DICOMFileReader.Read(Resources.explicitBigEndian);
            var elemCount = dcm.AllElements.Count;

            Assert.AreEqual(elemCount, 44);
        }
        public void RemoveElementTest()
        {
            var dcm = DICOMFileReader.Read(Resources.explicitLittleEndian);

            //Remove elements by tag
            dcm.Remove("00020000");
            dcm.Remove(TagHelper.SEGMENT_NUMBER);
        }
示例#6
0
        public void ReadMultipleFL()
        {
            var dcm            = DICOMFileReader.Read(Resources.MultpleFL);
            var vmGreaterThan1 = dcm.FindAll("300A030A");
            var el             = vmGreaterThan1[0] as AbstractElement <float>;

            Assert.IsTrue(el.Data_.Count > 1);
        }
示例#7
0
        /// <summary>
        /// Checks to see if the patient age is less than 89 years old
        /// </summary>
        /// <param name="file">Path to DICOM file containing patient information</param>
        /// <returns>boolean indication test</returns>
        public static bool YoungerThan89(string file)
        {
            //Check patient age - if 89 or older set anonymization options to
            //Not conserve patient age
            DICOMObject ageTest = DICOMFileReader.Read(file);
            Date        dob     = ageTest.FindFirst(TagHelper.PATIENT_BIRTH_DATE.CompleteID) as Date;
            int         age     = CalculateAge(dob);

            return(age < 89);
        }
示例#8
0
        public void ReplaceElementTest()
        {
            var dcm            = DICOMFileReader.Read(Resources.explicitLittleEndian);
            var directChildren = dcm.Elements;
            var allDescendants = dcm.AllElements;

            //Finds the first instance of the Group Length element (0002,0000)
            var firstInstance = dcm.FindFirst("00020000");

            //Finds all instances of the Group Length element (0002,0000)
            var allInstances = dcm.FindAll("00020000");

            //Finds all Code Value (0008,0100) elements that are children of Procedure Code Sequence Elements (0008,1032)
            var specificTree = dcm.FindAll(new Tag[] { TagHelper.Procedure​Code​Sequence, TagHelper.Code​Value });
示例#9
0
        /// <summary>
        /// Checks to see if the patient age is less than 89 years old
        /// </summary>
        /// <param name="file">Path to DICOM file containing patient information</param>
        /// <returns>boolean indication test</returns>
        public static bool YoungerThan89(string file)
        {
            //Check patient age - if 89 or older set anonymization options to
            //Not conserve patient age
            var ageTest = DICOMFileReader.Read(file);
            var dob     = ageTest.FindFirst(TagHelper.PatientBirthDate.CompleteID) as Date;

            if (dob != null)
            {
                var age = CalculateAge(dob);
                return(age < 89);
            }
            return(true);
        }
示例#10
0
        public void ToXML()
        {
            var dcm  = DICOMFileReader.Read(Resources.explicitLittleEndian);
            var xml  = dcm.ToXML();
            var dcm2 = DICOMObject.FromXML(xml);

            Assert.AreEqual(dcm.Elements.Count, dcm2.Elements.Count);
            Assert.AreEqual(dcm.AllElements.Count, dcm2.AllElements.Count);

            for (int i = 0; i < dcm.Elements.Count; i++)
            {
                var el1 = dcm.Elements[i];
                var el2 = dcm2.Elements[i];
                CollectionAssert.AreEquivalent(el1.DData_, el2.DData_);
            }
        }
示例#11
0
        public void WorkingWithMultiValuesTest()
        {
            var dcm = DICOMFileReader.Read(Resources.explicitLittleEndian);

            //Study time is a dateTime value
            var studyTime = dcm.FindFirst(TagHelper.STUDY_TIME) as Time;
            var time      = studyTime.Data; // data of type T (in this case system.datetime)

            //Patient position holds double values
            var positionEl = dcm.FindFirst(TagHelper.IMAGE_POSITION_PATIENT);
            var position   = positionEl as DecimalString;
            //Patient position contains an array of double values {X,Y,Z}
            var xyz = position.Data_; //Data as List<T> (in this case List<double>)
            var x   = xyz[0];
            var y   = xyz[1];
            var z   = xyz[2];
        }
示例#12
0
        public void PatientIdReplaceTest()
        {
            var dcm = DICOMFileReader.Read(Resources.explicitLittleEndian);
            var sel = dcm.GetSelector();

            sel.PatientID             = DICOMForge.PatientID;
            sel.PatientID.Data        = "12345";
            sel.PatientName.LastName  = "Flinstone";
            sel.PatientName.FirstName = "Fred";

            var anon = new PatientIdAnonymizer("Homer", "Simpson", "678910");

            anon.Anonymize(dcm);

            Assert.AreEqual(sel.PatientID.Data, "678910");
            Assert.AreEqual(sel.PatientName.LastName, "Simpson");
            Assert.AreEqual(sel.PatientName.FirstName, "Homer");
        }
示例#13
0
        public void WorkingWithSingleValuesTest()
        {
            var dcm = DICOMFileReader.Read(Resources.explicitLittleEndian);

            //The patient's name IDICOMElement
            var pName = dcm.FindFirst(TagHelper.PATIENT_NAME);

            //The patient's name strong typed for better data access
            var strongName = dcm.FindFirst(TagHelper.PATIENT_NAME) as PersonName;
            var firstName  = strongName.FirstName;
            var lastName   = strongName.LastName;

            //You can manipulate this way also
            strongName.FirstName = "Fred";
            strongName.LastName  = "Flinstone";

            //Generic casting
            var genericName = dcm.FindFirst(TagHelper.PATIENT_NAME) as AbstractElement <string>;
            var genValue    = genericName.Data; // returns Flinstone^Fred
        }
        public void ReplaceElementTest()
        {
            var dcm            = DICOMFileReader.Read(Resources.explicitLittleEndian);
            var directChildren = dcm.Elements;
            var allDescendants = dcm.AllElements;

            //Finds the first instance of the Group Length element (0002,0000)
            var firstInstance = dcm.FindFirst("00020000");

            //Finds all instances of the Group Length element (0002,0000)
            var allInstances = dcm.FindAll("00020000");

            //Finds all Code Value (0008,0100) elements that are children of Procedure Code Sequence Elements (0008,1032)
            var specificTree = dcm.FindAll(new Tag[] { TagHelper.PROCEDURE_CODE_SEQUENCE, TagHelper.CODE_VALUE });

            //Finds all elements that are of VR type PersonName
            var allPersonsNameElements = dcm.FindAll(Enums.VR.PersonName);

            //Whatever the referring physicians real name was, it is now Fred Flinstone
            var refName = new PersonName {
                FirstName = "Fred",
                LastName  = "Flinstone",
                Tag       = TagHelper.REFERRING_PHYSICIAN_NAME
            };

            dcm.Replace(refName);

            //Even if it doesn't exist yet, add it
            dcm.ReplaceOrAdd(refName);

            Assert.AreEqual(refName.Data, new PersonName
            {
                FirstName = "Fred",
                LastName  = "Flinstone"
            }
                            .Data);
        }
示例#15
0
        public void WriteBigEndian()
        {
            var dcm = DICOMFileReader.Read(Resources.explicitLittleEndian);
            var els = dcm.Elements.Count;

            byte[] bytes;

            using (var ms = new MemoryStream())
            {
                using (var dw = new DICOMBinaryWriter(ms))
                {
                    var settings = new DICOMWriteSettings()
                    {
                        TransferSyntax = Enums.TransferSyntax.EXPLICIT_VR_BIG_ENDIAN, DoWriteIndefiniteSequences = false
                    };
                    DICOMObjectWriter.Write(dw, settings, dcm);
                }
                bytes = ms.ToArray();
            }

            var dcm2 = DICOMFileReader.Read(bytes);

            Assert.AreEqual(dcm2.Elements.Count, els);
        }
示例#16
0
 public static DoseMatrix Load(string dcmFile)
 {
     return(new DoseMatrix(DICOMFileReader.Read(dcmFile)));
 }
示例#17
0
 public void Read()
 {
     var dcm       = DICOMFileReader.Read(@"C:\Users\Rex\Desktop\BASSIN - 8577\IM-0001-0001.dcm");
     var elemCount = dcm.AllElements.Count;
 }
示例#18
0
 /// <summary>
 /// Reads a DICOM file from a path
 /// </summary>
 /// <param name="filePath">the path to the file</param>
 /// <returns></returns>
 public static DICOMObject Read(string filePath)
 {
     return(DICOMFileReader.Read(filePath));
 }
示例#19
0
        public MainViewModel(ScriptContext context)
        {
            sc = context;

            DoAnonymizeStudyIDs = true;
            DoAnonymizeUIDs     = true;
            DateSettings        = ESAPIAnon.Settings.DateSettings.NULL_AGE;
            DoRemovePrivateTags = true;
            DoPlans             = DoStructures = DoDoses = DoImages = true;
            DoResendToDaemon    = false;
            FirstName           = "";
            LastName            = "";
            Id = "";

            AnonymizeCommand = new RelayCommand(() =>
            {
                //Get current patient id
                var id = GetPatientId();
                //Get current directory // Make patient folder if not exists
                var path = Helpers.AssemblyDirectory;
                var dir  = Path.Combine(path, id);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //Read settings file
                var ip      = "100.75.16.108";
                var scpAE   = "Db Daemon";
                var scpPort = 104;

                UpdateStatus("Getting DICOM Files from the Daemon...");
                CMove.GenerateDicomFiles(sc.Patient.Id, ip, scpPort.ToString(), scpAE, dir);
                UpdateStatus("Anonymizing...");
                var files    = Directory.GetFiles(dir);
                var dcms     = files.ToList().Select(f => DICOMFileReader.Read(f)).ToList();
                var settings = AnonymizeSettings.Generate(this);
                var que      = AnonymizationQue.Build(settings, dcms);
                dcms.ForEach(d => que.Anonymize(d));

                //Let user choose output
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.Description         = "Select DICOM File destination folder";
                fbd.RootFolder          = Environment.SpecialFolder.Desktop;
                DialogResult result     = fbd.ShowDialog();
                if (result == DialogResult.OK)
                {
                    var output = fbd.SelectedPath;
                    int i      = 0;
                    foreach (var dcm in dcms)
                    {
                        var fileOut = Path.Combine(output, string.Format("{0}.dcm", i));
                        i++;
                        DICOMFileWriter.WriteLittleEndian(fileOut, dcm);
                    }

                    //Clean up directory
                    Directory.Delete(dir, true);
                    UpdateStatus("Complete!");
                }
                else
                {
                    System.Windows.MessageBox.Show("You must select a file location!");
                }
            });
        }
示例#20
0
 /// <summary>
 /// Reads a DICOM file from a byte array
 /// </summary>
 /// <param name="file">the bytes of the DICOM file</param>
 /// <returns></returns>
 public static DICOMObject Read(byte[] file)
 {
     return(DICOMFileReader.Read(file));
 }
示例#21
0
 /// <summary>
 ///     Reads a DICOM file from a path
 /// </summary>
 /// <param name="filePath">the path to the file</param>
 /// <param name="trySyntax">the transfer syntax to use in case there is no metadata explicitly included</param>
 /// <returns>the DICOM Object</returns>
 /// <example>
 ///<code>
 ///var dcm = DICOMObject.Read("mydcm.dcm");
 ///</code>
 ///</example>
 public static DICOMObject Read(string filePath,
                                TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
 {
     return(DICOMFileReader.Read(filePath, trySyntax));
 }
示例#22
0
 public static RTDose Load(string dcmFile)
 {
     return(new RTDose(DICOMFileReader.Read(dcmFile)));
 }
示例#23
0
        public static Image <Gray, double> Read(string fileName)
        {
            var dicomData = DICOMFileReader.Read(fileName);

            return(Read(dicomData));
        }
示例#24
0
 /// <summary>
 ///     Reads a DICOM file from a byte array
 /// </summary>
 /// <param name="file">the bytes of the DICOM file</param>
 /// <param name="trySyntax">the transfer syntax to use in case there is no metadata explicitly included</param>
 /// <returns></returns>
 public static DICOMObject Read(byte[] file, TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
 {
     return(DICOMFileReader.Read(file, trySyntax));
 }
示例#25
0
        public static Image <Gray, double> Read(byte[] data)
        {
            var dicomData = DICOMFileReader.Read(data);

            return(Read(dicomData));
        }