1

I am currently using DCMTK in C++. I am quite new to this toolkit but, as I understand it, I should be able to read the window centre and width for normalisation purposes.

I have a DicomImage DCM_image object with my Dicom data. I read the values to an opencv Mat object. However, I now would like to normalise them. The following shows how I am reading and transferring the Data to an opencv Mat.

    DicomImage DCM_image("test.dcm");
    uchar *pixelData = (uchar *)(DCM_image.getOutputData(8));   
    cv::Mat image(int(DCM_image.getHeight()), int(DCM_image.getWidth()), CV_8U, pixelData);

Any help is appreciated. Thanks

user3126802
  • 419
  • 8
  • 19

1 Answers1

1

Reading window center and width is not difficult, however you need to use a different constructor and pass a DcmDataset to the image.

DcmFileFormat file;
file.loadFile("test.dcm");
DcmDataset* dataset = file.getDataset()
DicomImage image(dataset);
double windowCenter, windowWidth;
dataset->findAndGetFloat64(DcmTagKey(0x0010, 0x1050), windowCenter);
dataset->findAndGetFloat64(DcmTagKey(0x0010, 0x1051), windowWidth);

But actually I do not think it is a good idea to apply the windowing to the image upon loading. Windowing is something which should be adjustable by the user. The attributes Window Center and Window Width allow multiple values which can be applied to adjust the window to the grayscale range of interest ("VOI", Values of Interest).

If you really just want to create a windowed image, you can use your code to construct the image from the file contents and use one of the createXXXImage methods that the DicomImage provides.

HTH

Markus Sabin
  • 3,916
  • 14
  • 32
  • I see. What if I wanted to create a Dicom image using the windowcentre and windowwidth found by the above code? can it be done? – user3126802 Apr 05 '16 at 09:08
  • DicomImage has a setWindow method, then you can use createMonochromeImage() to obtain the result. You might want to have a look at the source code of dcm2pnm – Markus Sabin Apr 05 '16 at 10:45
  • Thank you @kritzel_sw, solved the problem with your suggestions! – user3126802 Apr 05 '16 at 19:00
  • You can also set one of the Window Center/Width values stored in the DICOM dataset using DicomImage::setWindow(unsigned long) and then call DicomImage::getWindow(double&, double&) to retrieve the currently set values. – J. Riesmeier Apr 06 '16 at 13:51
  • 1
    Also, instead of using DcmTagKey(0x0010, 0x1050) and DcmTagKey(0x0010, 0x1051), I would suggest to use the named constants DCM_WindowCenter and DCM_WindowWidth from "dcdeftag.h". – J. Riesmeier Apr 06 '16 at 13:54