使用 DCMTK 读取 3D Dicom 图像并将其转换为 OpenCV Mat

Read a 3D Dicom image with DCMTK and convert it to OpenCV Mat

我有一个 dicom 3D 图像,它是 [512,512,5](行、列、切片)。我想用 DCMTK 工具包 读取它并将其转换为 OpenCV Mat 对象。图片是16位unsigned int.

我的问题是:有谁知道将这个dicom图像转换成Mat对象的正确方法吗?如何使用 getOutputData?

方法正确读取所有切片

根据@Alan Birtles 的评论,可以在 getOutputData 方法中指定要阅读的帧。读取每一帧后,您只需将 Mat 对象合并为一个 Mat。

我写了这段代码来获取整个卷:

DicomImage *image = new DicomImage(file);

// Get the information
unsigned int nRows = image->getHeight();
unsigned int nCols = image->getWidth();
unsigned int nImgs = image->getFrameCount();

vector <Mat> slices(nImgs);

// Loop for each slice
for(int k = 0; k<nImgs; k++){

    (Uint16 *) pixelData = (Uint16 *)(image->getOutputData(16 /* bits */,k /* slice */));

    slices[k] = Mat(nRows, nCols, CV_16U, pixelData).clone();

}

Mat img;

// Merge the slices in a single img
merge(slices,img);

cout << img.size() << endl;
cout << img.channels() << endl;

// Output:
// [512 x 512]
// 5