使用DCMTK读取3D Dicom图像并将其转换为OpenCV Mat [英] Read a 3D Dicom image with DCMTK and convert it to OpenCV Mat

查看:656
本文介绍了使用DCMTK读取3D Dicom图像并将其转换为OpenCV Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a dicom 3D image which is [512,512,5] (rows, cols, slices). I want to read it with DCMTK toolkit and convert it to a OpenCV Mat object. The image is 16 bits unsigned int.

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

My question is: Does anyone know the correct way to convert this dicom image into a Mat object? How to properly read all the slices with the method getOutputData?

推荐答案

基于@Alan Birtles的注释,可以在getOutputData方法上指定要读取的框架.阅读完每一帧后,您只需将Mat对象合并为一个Mat.

Based on the comments of @Alan Birtles, there is the possibility to specify the frame you want to read on the getOutputData method. After reading each frame, you simply merge the Mat objects into a single 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

这篇关于使用DCMTK读取3D Dicom图像并将其转换为OpenCV Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆