## DICOM tags modification

A DICOM file is composed of a basic file structure which can be seen below:

The header consists of a 128 byte File Preamble, followed by a 4 byte DICOM prefix. The header sometimes may not be included in the file. It depends on the application and the vendor. So, if you wish to check out if a file is a DICOM one, you should not only check the header of the file. Actually, you should try to read the elements.

Preamble = 128 byte long  of unstructured data (on Tag or Length is specified, as in case of data elements). If Preamble is not used all 128 bytes are set to 00H.

Prefix = ‘D’ ‘I’ ‘C’ ‘O’ ‘M’ = 4 bytes long. Sometimes it can be found of “DICM”. It is also unstructure data.

Reading a DICOM file with the help of EvilDICOM:

using EvilDICOM.Core.Extensions;
using EvilDICOM.Core.Interfaces;
using EvilDICOM.Core.IO.Writing;
using EvilDICOM.Core.Selection;

namespace DTagModifier
{
class Program
{
static void Main(string[] args)
{
string patientFile = @"c:\temp\2405655408.dcm";
EvilDICOM.Core.DICOMObject patientPlan = DICOMObject.Read(patientFile);
}
}

Now if you want to read specific tags, you can do it in this way:

using EvilDICOM.Core.Extensions;
using EvilDICOM.Core.Interfaces;
using EvilDICOM.Core.IO.Writing;
using EvilDICOM.Core.Selection;

namespace DTagModifier
{
class Program
{
static void Main(string[] args)
{
// Read DICOM file
string patientFile = @"c:\temp\2405655408.dcm";
EvilDICOM.Core.DICOMObject patientPlan = DICOMObject.Read(patientFile);

// Use DICOMSelector class for well-known tags
var patientSelector = new DICOMSelector(patientPlan);
patientSelector.PatientName.FirstName = "Anonymized^^";
patientSelector.PatientName.LastName = "Empty";

// Write modified DICOM object to file
// using DICOMIOSettings.DefaultExplicit()
patientPlan.Write("Anonymized.dcm", DICOMIOSettings.DefaultExplicit());
}
}