how to modify image pixels in DICOM files using Imebra library?

771 views Asked by At

I use Imerba library to read DICOM files. I need acces to pixels so I can modify them in low level. Documentation says: "In order to access to the image's pixels you have to retrieve a data handler" and there's an example:

imbxUint32 rowSize, channelPixelSize, channelsNumber;
ptr<imebra::handlers::dataHandlerNumericBase> myHandler = presentationImage->getDataHandler(true, &rowSize, &channelPixelSize, &channelsNumber);

// Retrieve the image's size in pixels
imbxUint32 sizeX, sizeY;
presentationImage->getSize(&sizeX, &sizeY);

// Scan all the rows
imbxUint32 index(0);
for(imbxUint32 scanY = 0; scanY < sizeY; ++scanY)
{
    // Scan all the columns
    for(imbxUint32 scanX = 0; scanX < sizeX; ++scanX)
    {
            // Scan all the channels
            for(imbxUint32 scanChannel = 0; scanChannel < channelsNumber; ++scanChannel)
            {
            imbxInt32 channelValue = myHandler->getSignedLong(index++);

                    // Do something with the channel's value
                    //--------------------------------------
            }
    }

} I need the presentationImage object pixels to be changed. I've tried to change it in the way like:

myHandler->setSignedLong(index,255);

but it doesn't change presentationImage object and I'm now sure way. The Imebra documentation has only three examples and the classes and methods description is a bit raw. Google knows nothing as well. How to change pixel values in this object?

2

There are 2 answers

1
Paolo Brandoli On

When you modify the buffer you are modifying the uncompressed image: the original dicom structure still contains the compressed image.

In order to replace the image in the Dicom file you have to put the image back into the dataset using dataset::setImage after the dataHandler goes out of scope (the data is written into the image only when the dataHandler is destroyed)

1
madmortigan On

You need to have a MutableImage object and get a WritingDataHandlerNumeric handler via MutableImage::getWritingDataHandler

https://imebra.com/wp-content/uploads/documentation/html/html/imaging_classes.html#mutableimage