fo-dicom / fo-dicom

Fellow Oak DICOM for .NET, .NET Core, Universal Windows, Android, iOS, Mono and Unity
https://fo-dicom.github.io/stable/v5/index.html
Other
1.06k stars 640 forks source link

Methods for applying "Flip" and "Rotate" to pixel Data directly in dataset. #1302

Open LoCUBUS opened 2 years ago

LoCUBUS commented 2 years ago

What is, according to you, missing from fo-dicom? Please describe. I am using fo-dicom to create a tool to sort my DICOM images. Especially for QA purposes. Therefore I get a lot of unprocessed images. Depending on the system type and the individual mounting position of the detector the phantom image is not always aligned the same way. In many cases there is a rotation. E.g. on Siemens systems, the wall stand detector ist mounted 180° rotated. For the processed image, this is already corrected. So when loading both (processed and unprocessed) images they are not displayed in the same way. For my sorting tool, which is already quite powerful, I would love to add a feature that applies the tranformations directly to the dataset so that I can store a corrected version of the image. This should be possible without the need of rendering the image.

Describe the solution you'd like I would ask for methods to apply to a opened DicomFile.Dataset:

  1. Rotate - To avoid interpolation artifacts it would be sufficient to apply rotations of 90°, 180° and 270°.
  2. FlipV - To flip the image vertically (along the image rows)
  3. FlipH - to flip the image horizontally (along the image columns)

Describe possible alternatives or existing workarounds you've considered Workaround would be to

  1. Extract pixel data
  2. Convert to array
  3. reshape array
  4. apply transformations
  5. reconvert to raw pixel bytes
  6. replace pixel data
  7. replace rows and columns
mrbean-bremen commented 2 years ago

This would involve adapting at least Rows and Columns, SOPInstanceUID, probably ImageType and other properties like SeriesDescription. It should also be decided if it shall reside in the same series etc. I'm not sure if this something that should be done in the fo-dicom core itself. For me this sounds more like user code, or an add-on that uses fo-dicom. @gofal, @amoerie - what do you think?

LoCUBUS commented 2 years ago

@mrbean-bremen Your point regarding the effect on Series and other parameters is valid and may cause high effort. My request came from conventional X-Ray. In the particular case DX 4 processing. And there you normally get one Instance per Series.

I'm currently working on a dirty implementation for my sorting tool.

I was able to extract the PixelData as ushort using

DicomPixelData myPixelData = DicomPixelData.Create(DicomFileObject.Dataset);
var mypixelData_fromFactory = PixelDataFactory.Create(myPixelData, 0);
ushort[] pixels = ((GrayscalePixelDataU16)mypixelData_fromFactory).Data;

After that I do al the transformation(s).

My question now is: What is the best way to bring the transformed pixels array back into the DICOM file. I'm aware that for Rotate 90° and 270° I also have to change Rows and Columns. But I'm a little bit lost with the data types of the PixelData.