1. 程式人生 > 實用技巧 >Dicom多幀影像的單幀提取功能的實現

Dicom多幀影像的單幀提取功能的實現

Dicom 多幀影像一般都比較大,全部讀取的話對記憶體的要求很高,而且效率很低,所以在這種情況下需要一個單幀提取的方式。這裡分別介紹DCMTK和GDCM的單幀提取的方式:

DCMTK:

#include "dcmtk/config/osconfig.h" 
#include "dcmtk/dcmimgle/dcmimage.h" 

int main(int argc, char *argv[])
{
    OFLog::configure(OFLogger::INFO_LOG_LEVEL);

    DicomImage *image = new DicomImage("mf_image.dcm
", CIF_UsePartialAccessToPixelData, 0, 10 /* fcount */); if (image->getStatus() == EIS_Normal) { do { DCMIMGLE_INFO("processing frame " << image->getFirstFrame() + 1 << " to " << image->getFirstFrame() + image->getFrameCount()); }
while (image->processNextFrames()); } delete image; return 0; }

GDCM:

gdcm::ImageRegionReader reader;
reader.SetFileName(fileName);

std::vector<unsigned int> dims = gdcm::ImageHelper::GetDimensionsValue(reader.GetFile());

gdcm::BoxRegion box;
box.SetDomain(0, dims[0] - 1, 0, dims[1
] - 1, i, i); reader.SetRegion(box); size_t bufferLength = reader.ComputeBufferLength(); char* buffer = new char[bufferLength]; memset(buffer, 0x0, bufferLength); if (!reader.ReadIntoBuffer(buffer, bufferLength)) { std::cout << "讀取失敗" << std::endl; return 0; }

GDCM 處理的時候有個問題需要注意,用ImageRegionReader讀取出來後,再去呼叫reader.GetImage().GetTransferSyntax() 去獲取檔案語法,會發現該語法和原始Dicom檔案的語法不一致,所以如果需要獲取檔案語法,需要以下方法進行獲取:

const FileMetaInformation &header = reader.GetFile().GetHeader();
const TransferSyntax &ts = header.GetDataSetTransferSyntax();