简体   繁体   English

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

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

I have a dicom 3D image which is [512,512,5] (rows, cols, slices).我有一个 dicom 3D 图像,它是 [512,512,5](行、列、切片)。 I want to read it with DCMTK toolkit and convert it to a OpenCV Mat object.我想用DCMTK 工具包读取它并将其转换为OpenCV Mat 对象。 The image is 16 bits unsigned int.图像是 16 位无符号整数。

My question is: Does anyone know the correct way to convert this dicom image into a Mat object?我的问题是:有谁知道将这个 dicom 图像转换为 Mat 对象的正确方法? How to properly read all the slices with the method getOutputData ?如何使用getOutputData方法正确读取所有切片?

Based on the comments of @Alan Birtles, there is the possibility to specify the frame you want to read on the getOutputData method.根据@Alan Birtles 的评论,可以在getOutputData方法上指定要读取的帧。 After reading each frame, you simply merge the Mat objects into a single Mat.阅读每一帧后,您只需将 Mat 对象合并为单个 Mat。

I wrote this code to get the whole volume:我写了这段代码来获取整个卷:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM