How to save compressed pixels (compressed with my own encoder) back into DICOM image file using Imebra library?

时间:2017-04-25 14:28:52

标签: c++ image dicom imebra

I have my own image encoder and decoder. What I want is to read DICOM images, extract uncompressed image pixels, compress them using my encoder and then write those compressed pixels back in the DICOM file in place of uncompressed pixels. Decoder would do the opposite. Is this possible to do in Imebra? I can read tags and pixels, but after I compress them, I'm not sure how to put them back (they are currently in char* buffer), or if this is even possible. I'm using Imebra in C++.

Alternatively, it would be okay if I could create completely new DICOM file, but in that case I would need to easily transfer all the DICOM tags from the old file.

If this is not possible in Imebra, is there some other C++ library that allows this?

Edit: Thanks for the answer, Paolo. However, original DICOM image still remains unchanged (using second option). Can you say am I doing something obviously wrong here?

std::unique_ptr<imebra::DataSet> loadedDataSet(imebra::CodecFactory::load(imgNameM));
imebra::WritingDataHandlerNumeric* dataHandler = loadedDataSet->getWritingDataHandlerRaw(imebra::TagId(imebra::tagId_t::PixelData_7FE0_0010), 0); 
dataHandler->assign(buffer, size); 
delete dataHandler;  

loadedDataSet is not empty, I checked with bufferExists.

Edit 2: Yes, I didn't save it. Now I added that line and managed to modify PixelData element which was solves my original problem. Thanks. However, some other parts of the file are now automatically also changed. More than 100 empty bytes are added at the beginning of the file, although this doesn't bother me that much. What bothers me is that (0008,0005) Specific Character Set tag is now added and its value isn't set (it's empty) which then causes CharsetConversionNoTableError when trying to read tags of that modified file. If I remove that tag manually and fix the group length, I can read tags normally. Is there a possibility to avoid this behavior?

1 个答案:

答案 0 :(得分:1)

Imebra已经为无损jpeg,基线和扩展jpeg,RLE提供了编码器/解码器。

有几种方法可以将自己的编解码器添加到Imebra:

  • 从imebra :: implementation :: codecs :: imageCodec
  • 派生一个类
  • 或将图像编码到char缓冲区中,然后使用imebra::DataSet::getWritingDataHandlerRaw将其添加为原始内容,这允许您编写标记原始内容。 getWritingDataHandlerRaw返回WritingDataHandlerNumeric。使用WritingDataHandlerNumeric::assign将字节缓冲区移动到数据处理程序中,然后删除数据处理程序以使其将内容提交到数据集中。
  • 库附带的示例changeTransferSyntax显示如何使用源数据集中的所有相同标记创建新数据集,但使用不同的传输语法(包括不同的图像压缩)