【问题标题】:Read a 3D Dicom image with DCMTK and convert it to OpenCV Mat使用 DCMTK 读取 3D Dicom 图像并将其转换为 OpenCV Mat
【发布时间】:2020-04-27 04:45:47
【问题描述】:

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

我的问题是: 有谁知道将此 dicom 图像转换为 Mat 对象的正确方法?如何使用getOutputData方法正确读取所有切片?

【问题讨论】:

  • getOutputData(16) 将仅返回帧 0 的数据。 DicomImage 中没有方法可以将所有图像放在一个缓冲区中。
  • 我猜你必须一次检索一个帧并以某种方式将它们输入到 openCV 中,恐怕我不熟悉 openCV
  • getOutputData(16, 1) 返回第二帧,见reference

标签: c++ opencv dcmtk


【解决方案1】:

基于@Alan Birtles 的cmets,可以在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

【讨论】:

  • 如果这行得通,我会感到惊讶,因为从 getOutputData 返回的指针仅在下一次调用 getOutputData 之前有效,我不认为 Mat 正在复制传入的数据.另外,为什么要单独对待切片 0?你不能把你的for循环改成for(int k = 0吗?
  • 文档没有提到它复制:docs.opencv.org/trunk/d3/d63/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-03
  • 2020-09-15
  • 2016-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多