使用C++调用DCMTK读取RT dose 文件并且输出到excel中。

本文介绍了一个使用DCMTK库的C++函数,该函数从DICOMRT剂量文件中提取像素数据并将其导出到CSV文件,以便于数据分析。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <fstream>
#include "dcmtk/dcmdata/dctk.h"

void exportRtDoseToCsv(const char* doseFilePath, const char* outputCsvPath) {
    // Load the RT dose file
    DcmFileFormat doseFile;
    if (doseFile.loadFile(doseFilePath).good()) {
        // Get the pixel data element
        DcmElement* pixelDataElement = nullptr;
        if (doseFile.getDataset()->findAndGetElement(DCM_PixelData, pixelDataElement).good()) {
            // Get the pixel data
            Uint16* pixelData = nullptr;
            if (pixelDataElement->getUint16Array(pixelData).good()) {
                // Get the number of rows, columns, and Frames
                Uint16 rows = 0, columns = 0;
                int32_t frames = 0;
                if (doseFile.getDataset()->findAndGetUint16(DCM_Rows, rows).good() &&
                    doseFile.getDataset()->findAndGetUint16(DCM_Columns, columns).good() &&
                    doseFile.getDataset()->findAndGetSint32(DcmTagKey(0x0028, 0x0008), frames).good()) {
                    // Create the output CSV file

                    std::ofstream csvFile(outputCsvPath);
                    if (csvFile.is_open()) {
                        // Write the pixel data to the CSV file for each slice
                        for (Uint16 slice = 0; slice < frames; ++slice) {
                            csvFile << "Slice " << slice + 1 << std::endl;
                            for (Uint16 row = 0; row < rows; ++row) {
                                for (Uint16 column = 0; column < columns; ++column) {
                                    csvFile << pixelData[(slice * rows * columns) + (row * columns) + column] << ",";
                                }
                                csvFile << std::endl;
                            }
                            csvFile << std::endl;
                        }
                        csvFile.close();
                        std::cout << "RT dose data has been successfully exported to a CSV file." << std::endl;
                    }
                    else {
                        std::cout << "Unable to create the output CSV file." << std::endl;
                    }
                }
                else {
                    std::cout << "Unable to retrieve rows, columns, and Frames information." << std::endl;
                }
            }
            else {
                std::cout << "Unable to retrieve the pixel data." << std::endl;
            }
        }
        else {
            std::cout << "Pixel data element not found." << std::endl;
        }
    }
    else {
        std::cout << "Unable to load the RT dose file." << std::endl;
    }
}

int main() {
    const char* doseFilePath = "D:\\钉钉下载\\eclipse-8.1.20-phantom-ent\\Original\\RD.1.2.246.352.71.7.2088656855.452404.20110921073629.dcm";  // Replace with the actual RT dose file path
    const char* outputCsvPath = "D:\\dcmtktest\\output.csv";  // Replace with the output CSV file path
    exportRtDoseToCsv(doseFilePath, outputCsvPath);

    return 0;
}


 

  • 24
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大孔隆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值