cornerstone icon indicating copy to clipboard operation
cornerstone copied to clipboard

Anonymise Dicom Pixel Data

Open Neuroforge opened this issue 5 years ago • 1 comments

Hello,

We have been working with cornerstonejs for awhile and it's helped us ever so much. So thank you.

It appears that de-identification of image has been looked at in the past but only handles specified tags.

https://rawgit.com/cornerstonejs/dicomParser/master/examples/simpleDeIdentify/index.html

We would like to alter the pixel data and remove some of the patient identifiers that can be sometimes found in the images.

Is is possible to completely remove the pixel data and then download the file.

Is it possible to edit/draw on the pixel data? Is it possible to handle pixel data that under some compression? If altered on an HTML canvas, can the new pixel data replace the old data?

const pixelElement = dataSet.elements.x7fe00010;

if (pixelElement.encapsulatedPixelData) {
    const fisrtFragmentPos = pixelElement.fragments[0].position;
    const lastFragmentEndPos =
        pixelElement.fragments[pixelElement.fragments.length - 1].length +
        pixelElement.fragments[pixelElement.fragments.length - 1].position;
    // get the Sequence Delimiter Item (FFFE,E0DD) to assure encapsulated Dicom file working
    for (let i = 0; i < 8; i++) {
        dataSet.byteArray[fisrtFragmentPos + i] =
            dataSet.byteArray[lastFragmentEndPos + i];
    }
    // remove the pixel data
    dataSet.byteArray = dataSet.byteArray.slice(0, fisrtFragmentPos + 8);
} else {
    // remove the pixel data
    dataSet.byteArray = dataSet.byteArray.slice(
        0,
        pixelElement.dataOffset
    );
}

Downloading the altered Dicom should be as simple as....

 var blob = new Blob([dataSet.byteArray], {type: "application/dicom"});
        var url = window.URL.createObjectURL(blob);
        window.open(url);

Regards,

Neuroforge avatar Apr 28 '20 06:04 Neuroforge

Unless you're using cornerstone for input as to which portions of the pixel data should be cleared, I imagine you could do most of this with dicom-parser / dcmjs.

It would be nice if they were a little more reusable, but I think you would need the codecs in cornerstone-wado-image-loader to decode the images, modify the raw pixels, and then reencode them (which those particulars may not fully support).

You probably wouldn't do this on demand? I imagine it would be a part of your data ingress. In that case, there may be more mature libraries (outside of JS) you could leverage.

(I'm spitballing -- Hopefully others chime in with thoughts/suggestions)

dannyrb avatar Apr 28 '20 10:04 dannyrb