How to Rotate/Flip DicomImage?
It's dead easy to Rotate/Flip Images using DicomObjects, change the FlipState and RotateState properties as below:
DicomImage.FlipState = doFlipHorizontal DicomImage.RotateState = doRotate180
All possible enumerations for FlipState and RotateState are:
doFlipBoth: Image is mirrored vertically and horizontally doFlipHorizontal: Image is mirrored horizontally doFlipNormal: Normal doFlipVertical: Image is mirrored vertically doRotateNormal: Normal doRotate180: Image is 180° doRotateLeft: Image is rotated 90° counter-clockwise doRotateRight: Image is rotated 90° clockwise Default values for FlipState and RotateState are doFlipNormal and doRotateNormal
Please note, only display within a DicomViewer is altered by these properties. Storage and transmission are NOT affected. Clearly, these properties interact, as for example, RotateState=doRotate180 has the same effect as FlipState=doFlipBoth. Conceptually, the flip is performed first, followed by any rotation. These properties are over-ridden if a Presentation State is applied.
How to make those conversions permanent?
Two approaches to achieve this. The best one is to use Presentation_State, where all display settings, like Labels, Zooming, Scrolling, Flip, Rotate, etc. are stored and saved as a separate file. Using Presentation State is recommended as no Image information will be altered, the original image will stay intact. In places where Presentation States are not supported, an alternative approach (DicomImage.SubImage) can be used to make all display settings (not just flip and rotate) permanent. Following VB Code shows how to do it:
' Change FlipState, RotateState, etc. of the Current Image DicomViewer1.CurrentImage.FlipState = doFlipHorizontal DicomViewer1.CurrentImage.RotateState = doRotateLeft ' Define a new DicomImage and call the SubImage function Dim newImage As New DicomImage Set newImage = DicomViewer1.CurrentImage.SubImage(0, 0, 0, 0, 1, 1) ' Save the new Image onto Disk newImage.WriteFile filePath, true, "1.2.840.10008.1.2.1"
When the original image is flipped and/or rotated, the SubImage will be similarly modified, and the coordinates used for the offsets and sizes apply in the rotated/flipped coordinate space. Check the help file for more information about SubImage function.