如何使用 imebra 将 RAW 图像转换为 DICOM 图像?

How can I convert RAW image to DICOM image using imebra?

我是 imebra 的新手,想将原始图像转换为 DICOM 图像。我已经将 imebra 库编译到我的虚拟机 (ubuntu 16.04),并按照网站上的教程进行操作。我发现他们没有显示如何将原始图像转换为 DICOM 图像。

谁能帮帮我或者告诉我转换的过程?

#include <imebra/imebra.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <memory>

using namespace std;
int main()
{   

    //creat read stream  
    using namespace puntoexe;
    ptr<stream> readStream(new stream);
    readStream->openFile(NSStringToStringW(imagePath), std::ios::in);


    // Create dataset
    streamReader reader =new streamReader(readStream);
    imebra::dataSet testDataSet = imebra::codecs::codecFactory::getCodecFactory()->load(reader);

    // Set Tags
    testSet->setString(0x0010,0,0x0010,0,"testSrt0");
    testSet->setString(0x0010,0,0x0010,1,"testSrt1");

    // Load jpeg
    std::unique_ptr<imebra::DataSet> testSet(imebra::CodeFcactory::load("/home/lixingyu/care.raw"));

    // Save as DICOM
    imebra::CodecFactory::save(testSet, "/home/lixingyu/care.dcm", imebra::codecType_t::dicom);
    */
    return 0;
}

我不太确定上面的代码。这个过程有什么问题吗?? 当我尝试此代码时:using namespace puntoexe; 发生错误:

"error: ‘puntoexe’ is not a namespace-name" and "ptr" was also fault.

您忘记包含一个包含 puntoexe 命名空间和 ptr(可能)在其中的头文件。

编辑:在进一步研究中,您似乎使用的是旧教程。 puntoexe::ptr 不再使用,应由标准智能指针代替。

// Load jpeg
std::unique_ptr<imebra::Dataset> 
testDataset(imebra::CodecFactory::load("/path/to/jpegfile.jpg"));

// Save as Dicom
imebra::CodecFactory::save(testDataset, "/path/to/file.dcm", 
imebra::codecType_t::dicom);

您使用的是相当旧版本的 Imebra。

使用 Imebra 4 和 5,您可以:

  • 创建图像对象
  • 用原始数据填充图像对象
  • 创建 DICOM 数据集
  • 将图像添加到 DICOM 数据集
  • 填写所有必要的 DICOM 标签(例如 sop class、实例、患者姓名等)
  • 保存 DICOM 数据集

在代码中,使用 Imebra5:

include <imebra/imebra.h>

// Create an image 500 pixels wide, 400 pixels height,
// each sample is a 16 bit unsigned value, the colorspace
// is monochrome_2, the higher bit used is 15
imebra::MutableImage image(500, 400, imebra::bitDepth_t::depthU16, "MONOCHROME2", 15);

// We fill the image with data
{
    // We use a writing data handler to write into the image.
    // The data is committed into the image only when the writing
    // data handler goes out of scope.
    imebra::WritingDataHandlerNumeric writeIntoImage(image.getWritingDataHandler());

    for(size_t y(0); y != 400; ++y)
    {
        for(size_t x(0); x != 500; ++x)
        {
            // This method is slow, you can access directly the memory
            // with writeIntoImage.assign() or getMemory()
            writeIntoImage.setUnsignedLong(y * 500 + x, pixelValue);
        }
    }
}

// We specify the transfer syntax and the charset
imebra::charsetsList_t charsets;
charsets.push_back("ISO 2022 IR 6");
imebra::MutableDataSet dataSet("1.2.840.10008.1.2.1", charsets);

// Add the image to the dataset
dataSet.setImage(0, image,  imebra::imageQuality_t::veryHigh);

// Set the patient name
dataSet.setUnicodePatientName(imebra::TagId(imebra::tagId_t::PatientName_0010_0010), imebra::UnicodePatientName(L"Patient^Name", "", ""));

// Save to a file
imebra::CodecFactory::save(dataSet, "dicomFile.dcm", imebra::codecType_t::dicom);

Imebra 4 代码类似,但函数返回指针而不是对象。

免责声明:我是 Imebra 的作者