This article will show you how to create an Ultrasound image from imported pixel data.

DICOM Ultrasound images contain multiple regions specifying the different parts to the generated image. Each of these regions has it’s own pixel geometry and each region can take priority over another if they overlap. See C.8.5.5 US Region Calibration Module for details.

DicomObjects supports reading and creating these formats fully, and our Viewer will respect these regions for ROI measurement and pixel inspection.

To create the region definitions a sequence of regions is added to the dataset within the attribute Sequence of Ultrasound Regions(0018,6011). Each region must specify a minimum number of Attributes, with additional parameters required depending on the type of the region. Below we are describing a single region of pixel data as Tissue echo as the simplest case.

// make simple image with arbitrary JPG content, and label it as US
 var image = new DicomImage();
 image.Import(@"Tulips.jpg");
 image.SOPClass = SOPClasses.UltrasoundMultiframe;
    
 // add line and confirm that measurement is in "pixels"
 var label = new DicomLabel()
 {
	Area = new RectangleF(10, 10, 30, 40),  // 30,40,50 pythagorean triangle
	LabelType = LabelType.Line,
	ScaleMode = ScaleMode.Image
 };
    
 // this should be 50 pixels (no calibration)
 MessageBox.Show($"Length without region = {label.ROILength(image)} {label.ROIDistanceUnits(image)}");  
    
 // Add region as per DICOM rules for US images
 DicomDataSet region = new DicomDataSet();
    
 // size of region (in this case the whole image)
 region.Add(Keyword.RegionLocationMinX0, 0);
 region.Add(Keyword.RegionLocationMinY0, 0);
 region.Add(Keyword.RegionLocationMaxX1, image.Size.Width);
 region.Add(Keyword.RegionLocationMaxY1, image.Size.Height);
    
 // Crazy as it might seem, DICOM insists on CENTI-metres in this mode
 // but for consistency with the rest of DICOM, we convert and return mm in the ROI functions
 region.Add(Keyword.PhysicalUnitsXDirection, 0x3); // 3 is the code for cm, as opposed to cm/s, seconds etc.
 region.Add(Keyword.PhysicalUnitsYDirection, 0x3); // see part 3 - section C.8.5.5.1.15 for the list
 region.Add(Keyword.PhysicalDeltaX, 0.05); //= 0.5 mm
 region.Add(Keyword.PhysicalDeltaY, 0.05);
    
 //These are critical to the current region and how it is rendered
 region.Add(Keyword.RegionSpatialFormat, 0x1); // = 2D image
 region.Add(Keyword.RegionDataType, 0x1); // = "tissue"
 region.Add(Keyword.RegionFlags, 0x0); // no special handling
    
 image.DataSet.Add(Keyword.SequenceOfUltrasoundRegions, new DicomDataSetCollection { region });
    
 // now repeat measurement
 // this should be 25mm (0.5 mm/pixel)
 MessageBox.Show($"Length WITH region = {label.ROILength(image)} {label.ROIDistanceUnits(image)}")