如何使用Imebra库从jpeg转换/创建dicom图像?

时间:2016-06-23 13:14:23

标签: c++ ios objective-c iphone dicom

我想在iOS平台上使用imebra库创建将jpeg图像转换为dicom图像。在库的目标c示例中,给出了将dicom转换或读取为jpeg的步骤,但是,我正在阅读文档并尝试反过来(即jpeg到dicom)。我没有c ++的背景所以任何帮助将不胜感激。链接到库和文档:

1。https://imebra.com

2。https://imebra.com/wp-content/uploads/documentation/imebra_build_2013-10-30_10-00-11/html/dicom2jpeg_2dicom2jpeg_8cpp-example.html

以下一些基本代码,提前感谢。

-(void)createDcmFromJpg
{

     NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"test2" ofType:@"jpeg"];

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

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

    //set Tags
    testDataSet->setString(0x0010, 0, 0x0010, 0, "testStr");
    testDataSet->setString(0x0010, 0, 0x0010, 1, "testStr1");

   //Next step/steps ?
}

1 个答案:

答案 0 :(得分:1)

imebra :: dataSet代表Dicom标签的集合。

当你读取文件(jpeg或dicom)时,Imebra会创建一个dataSet,它是一组Dicom标签。

当读取Dicom文件时,dataSet将完全镜像存储在Dicom文件中的标签,而在读取jpeg图像时,Imebra将创建一个包含嵌入jpeg图像的正确dicom标签的dataSet:所有需要的Dicom标签将已经在dataSet中,您可以添加自己的(如患者姓名等)。

下一步是将dataSet保存到Dicom流:

使用Imebra V4(当前):

// 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 2015(遗产):

// Open the Dicom file for writing
ptr<stream> writeStream(new stream);
writeStream->openFile(NSStringToStringW(dicomfilepath), std::ios::out);

// Declare the writer (will take care of writing into the stream)
ptr<streamWriter> writer (new streamWriter(writeStream));

// Use the dicom codec to write the dataSet into the file
ptr<imebra::codecs::codec> dicomCodec(new imebra::codecs::dicomCodec);
dicomCodec->write(writer, testDataSet);