Pixel shifting is a process used in conjunction with Mask_Subtraction to correct for movement of the patient between exposures, so as to give the best alignment and therefore the best masking of fixed structures possible. In general, there needs to be a different shift factor for each frame in an image (if there has been movement between the mask and the image frames, then there is also likely to be movement between the image frames!)
Due to this complexity, Pixel shifting is not directly supported in the COM_version of DicomObjects through simple properties (like Mask or Maskframe for unshifted subtraction) but is is supported through use of the DICOM "Mask Subtraction Sequence" (Mask Module) which may be present in either the image itself, or more commonly in a DICOM Presentation_state object. This sequence allows a great deal of complexity and is used internally by DicomObjects, and the following VB code gives an idea how to use it.
Note: This example uses modification of the image as stored in memory, and developers should be careful as to whether or not they wish to persist any such modification in images sent or stored elsewhere. In general, modification of existing images is not recommended!
This example uses two items in the sequence to indicate that:
- Frames 1-5 should not be subtracted (they are not listed in either item)
- Frames 6 to 10 should have frame 4 subtracted, with a shift of 1 pixel vertically and -2 horizontally
- Frames 11 to 15 should have frame 5 subtracted, with a shift of 0 pixels vertically and 3 horizontally
More complex examples are also supported using "Time Interval Differencing" or averaging of multiple mask frames, but these are beyond the scope of this article - see DICOM Part 3 section C.7.6.10 for more information.
Dim shift(1 To 2) As Single ' need an array to hold two shift values Dim range(1 To 2) As Single ' need an array to hold ends of frame range Dim MaskSequence As New DicomDataSets
The first range:
Dim MaskSequenceItem1 As New DicomDataSet MaskSequenceItem1.Attributes.Add &H28, &H6101, "AVG_SUB" ' fixed value to indicate normal subtraction range(1) = 6 range(2) = 10 MaskSequenceItem1.Attributes.Add &H28, &H6102, range MaskSequenceItem1.Attributes.Add &H28, &H6110, 4 ' the mask frame shift(1) = 1 ' note that Y comes first! shift(2) = -2 MaskSequenceItem1.Attributes.Add &H28, &H6114, shift MaskSequence.Add MaskSequenceItem1
The second range:
Dim MaskSequenceItem2 As New DicomDataSet MaskSequenceItem2.Attributes.Add &H28, &H6101, "AVG_SUB" ' fixed value to indicate normal subtraction range(1) = 11 range(2) = 15 MaskSequenceItem2.Attributes.Add &H28, &H6102, range MaskSequenceItem2.Attributes.Add &H28, &H6110, 5 ' the mask frame shift(1) = 0 ' note that Y comes first! shift(2) = 3 MaskSequenceItem2.Attributes.Add &H28, &H6114, shift
Add to the image, and suggest use of subtraction mode for viewing
im.Attributes.Add &H28, &H6100, MaskSequence im.Attributes.Add &H28, &H1090, "SUB" ' indicate to display in subtraction mode
NOTE: Due to a bug in earlier versions of DicomObjects, only the first such sequence will actually be considered in versions before 4.3.54.x