簡體   English   中英

使用 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 位無符號整數。

我的問題是:有誰知道將這個 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM