1
votes

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
Did you save the file? imebra::CodecFactory::save(*loadedDataSet, "test.dcm", imebra::codecType_d::dicom). Be aware that changing the image raw data may require changes in other tags in order to be interpreted correctly, including the transfer syntax of the DataSetPaolo Brandoli
@Paolo Brandoli Yes, skipped that. I added that and can now modify the PixelData.Jet Black

1 Answers

1
votes

Imebra already provides the encoder/decoder for lossless jpeg, baseline and extended jpeg, RLE.

There are several ways of adding your own codec to Imebra:

  • derive a class from imebra::implementation::codecs::imageCodec
  • or encode an image into a char buffer, then add it as raw content using imebra::DataSet::getWritingDataHandlerRaw which allows you to write the tag raw content. getWritingDataHandlerRaw returns a WritingDataHandlerNumeric. Use WritingDataHandlerNumeric::assign to move the bytes buffer into the data handler, then delete the data handler to cause it to commit its content into the dataset.
  • The example changeTransferSyntax that comes with the library shows how to create a new dataset with all the same tags from the source dataset but with a different transfer syntax (including a different image compression)