ITK生成mhd文件(附加额外Tag信息)

7 篇文章 0 订阅
这段代码展示了如何使用ITK库将DICOM系列转换为MHD文件,并设置压缩选项。它首先从DICOM路径创建ITK图像,然后利用ImageFileWriter将图像写入MHD格式,同时设置了元数据,包括像素深度和宽度信息。
摘要由CSDN通过智能技术生成

bool writeMhdFile(const char* dicomPath, const char *mhdFileName, bool useCompression)
{
    typedef itk::Image<short, 3> ImageType;
    ImageType::Pointer image;
    if (!dicomSeriesToITKImage(dicomPath, image))
    {
        return false;
    }

    typedef itk::ImageFileWriter<ImageType> ImageWriterType;
    ImageWriterType::Pointer writer = ImageWriterType::New();
    writer->SetFileName(mhdFileName);
    writer->SetInput(image);
    //writer->SetImageIO(itk::MetaImageIO::New());
    itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();
    itk::MetaDataDictionary outputDictionaty = metaWriter->GetMetaDataDictionary();
    itk::EncapsulateMetaData<std::string>(
        outputDictionaty, std::string("0028|1051"),
        std::to_string(350));//TODO from dcm
    itk::EncapsulateMetaData<std::string>(
        outputDictionaty, std::string("0028|1050"),
        std::to_string(40));//TODO from dcm
    metaWriter->SetMetaDataDictionary(outputDictionaty);
    writer->SetImageIO(metaWriter);
    image->SetMetaDataDictionary(outputDictionaty);
    writer->SetUseCompression(useCompression);
    try
    {
        writer->Update();
    }
    catch (itk::ExceptionObject &ex)
    {
        std::cout << " failed to write mhd file to folder: " << mhdFileName << ex << std::endl;
        return false;
    }

    return true;
}

参考代码

https://itk.org/Doxygen/html/SphinxExamples_2src_2Core_2Common_2StoreNonPixelDataInImage_2Code_8cxx-example.html 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值