public static DicomDataset CreateRandomInstanceDataset( string studyInstanceUid = null, string seriesInstanceUid = null, string sopInstanceUid = null, string sopClassUid = null) { var ds = new DicomDataset(DicomTransferSyntax.ExplicitVRLittleEndian) { { DicomTag.StudyInstanceUID, studyInstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SeriesInstanceUID, seriesInstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SOPInstanceUID, sopInstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SOPClassUID, sopClassUid ?? TestUidGenerator.Generate() }, { DicomTag.BitsAllocated, (ushort)8 }, { DicomTag.PhotometricInterpretation, PhotometricInterpretation.Monochrome2.Value }, { DicomTag.PatientID, TestUidGenerator.Generate() }, }; return(ds); }
public static DicomFile GenerateDicomFile( string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid, string sopClassUid, int rows, int cols, TestFileBitDepth bitDepth, string transferSyntax, bool encode, int frames = 1, string photometricInterpretation = null) { DicomTransferSyntax initialTs = DicomTransferSyntax.ExplicitVRLittleEndian; if (!encode) { initialTs = DicomTransferSyntax.Parse(transferSyntax); } var rand = new Random(); var dicomFile = new DicomFile( new DicomDataset(initialTs) { { DicomTag.StudyInstanceUID, studyInstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SeriesInstanceUID, seriesInstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SOPInstanceUID, sopInstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SOPClassUID, sopClassUid ?? TestUidGenerator.Generate() }, { DicomTag.Rows, (ushort)rows }, { DicomTag.Columns, (ushort)cols }, { DicomTag.PhotometricInterpretation, photometricInterpretation ?? PhotometricInterpretation.Monochrome2.Value }, { DicomTag.BitsAllocated, (ushort)bitDepth }, { DicomTag.WindowWidth, ((bitDepth == TestFileBitDepth.EightBit) ? "256" : "65536") }, { DicomTag.WindowCenter, ((bitDepth == TestFileBitDepth.EightBit) ? "128" : "32768") }, { DicomTag.AccessionNumber, rand.Next(11111111, 19999999) }, { DicomTag.PatientID, TestUidGenerator.Generate() }, }); var pixelData = DicomPixelData.Create(dicomFile.Dataset, true); pixelData.SamplesPerPixel = 1; pixelData.BitsStored = (ushort)bitDepth; pixelData.HighBit = (ushort)(bitDepth - 1); pixelData.PixelRepresentation = PixelRepresentation.Unsigned; for (int i = 0; i < frames; i++) { var buffer = new MemoryByteBuffer( (bitDepth == TestFileBitDepth.SixteenBit) ? GetBytesFor16BitImage(rows, cols, i) : GetBytesFor8BitImage(rows, cols, i)); pixelData.AddFrame(buffer); } if (encode && transferSyntax != DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID) { var transcoder = new DicomTranscoder( dicomFile.Dataset.InternalTransferSyntax, DicomTransferSyntax.Parse(transferSyntax)); dicomFile = transcoder.Transcode(dicomFile); } return(dicomFile); }
public static DicomDataset CreateRandomInstanceDataset( PatientInstance pI) { Random rand = new Random(); var studyTime = DateTime.Parse(pI.PerformedProcedureStepStartDate).AddMinutes(-10); var dicomTime = studyTime.ToString("HHmmss.fffff"); var procedureTime = DateTime.Parse(pI.PerformedProcedureStepStartDate); var procedureDate = studyTime.ToString("yyyyMMdd"); var dicomProcedureTime = studyTime.ToString("HHmmss.fffff"); var age = int.Parse(pI.PatientAge); string dicomAge = null; if (age > 9) { dicomAge = "0" + age.ToString() + "Y"; } else { dicomAge = "00" + age.ToString() + "Y"; } var occupation = pI.PatientOccupation.Length > 16 ? pI.PatientOccupation.Substring(0, 16) : pI.PatientOccupation; var laterality = new List <string> { "R", "L" }; var physicianName = pI.PhysicianName.Split()[0] + "^" + pI.PhysicianName.Split()[1]; var name = pI.Name.Split()[0] + "^" + pI.Name.Split()[1]; var ds = new DicomDataset(DicomTransferSyntax.ExplicitVRLittleEndian) { { DicomTag.StudyInstanceUID, pI.StudyUid ?? TestUidGenerator.Generate() }, { DicomTag.SeriesInstanceUID, pI.SeriesUid ?? TestUidGenerator.Generate() }, { DicomTag.SOPInstanceUID, pI.InstanceUid ?? TestUidGenerator.Generate() }, { DicomTag.SOPClassUID, TestUidGenerator.Generate() }, { DicomTag.BitsAllocated, (ushort)8 }, { DicomTag.PhotometricInterpretation, PhotometricInterpretation.Monochrome2.Value }, { DicomTag.PatientID, pI.PatientId ?? TestUidGenerator.Generate() }, { DicomTag.SpecificCharacterSet, "ISO_IR 100" }, { DicomTag.StudyDate, procedureDate }, { DicomTag.SeriesDate, procedureDate }, { DicomTag.StudyTime, dicomTime }, { DicomTag.SeriesTime, dicomTime }, { DicomTag.AccessionNumber, pI.AccessionNumber }, { DicomTag.InstanceAvailability, "ONLINE" }, { DicomTag.Modality, pI.Modality }, { DicomTag.StudyDescription, pI.StudyDescription }, { DicomTag.SeriesDescription, pI.StudyDescription }, { DicomTag.NameOfPhysiciansReadingStudy, physicianName }, { DicomTag.ReferringPhysicianName, physicianName }, { DicomTag.PatientName, name }, { DicomTag.PatientBirthDate, pI.PatientBirthDate }, { DicomTag.PatientSex, pI.PatientSex }, { DicomTag.PatientAge, dicomAge }, { DicomTag.PatientWeight, pI.PatientWeight }, { DicomTag.Occupation, occupation }, { DicomTag.StudyID, rand.Next(10000000, 100000000).ToString() }, { DicomTag.SeriesNumber, pI.SeriesIndex }, { DicomTag.InstanceNumber, pI.InstanceIndex }, { DicomTag.Laterality, laterality.RandomElement() }, { DicomTag.PerformedProcedureStepStartDate, procedureDate }, { DicomTag.PerformedProcedureStepStartTime, dicomProcedureTime }, }; return(ds); }