dcmjs-org / dcmjs

Javascript implementation of DICOM manipulation
https://dcmjs.netlify.com/
MIT License
287 stars 108 forks source link

Issue with pixel redaction for JPEGLoseless type #376

Open syedkibrahim opened 6 months ago

syedkibrahim commented 6 months ago

We are trying to redact a portion of a DICOM file by setting the pixel value to 0. The file we are trying with is a 16-bit JPEG2000Loseless type (Transfer Syntax ID - 1.2.840.10008.1.2.4.90)

But instead of removing the selected region, it is showing a white noise at the top of the image. 3

Using DicomParser and saw that this file is having encapsulatedPixelData: true, not sure if that is the reason. 2

But this approach is working fine for other DICOM file types that we have tested. The steps we are using are as follows:

We are generating the buffer for the file and storing it in a variable named buffer.

const DicomDict = dcmjs.data.DicomMessage.readFile(buffer);
const pixelDataElement = DicomDict.dict['7FE00010'];
const pixelArrayBuffer = pixelDataElement.Value;

// we are getting the x and y pointer location of the selected area
let bit16Array = new Uint16Array(pixelArrayBuffer[0]);
for (let y = y1; y < y2; y++) {
      for (let x = x1; x < x2; x++) {
            const index = y * rows + x;
            bit16Array[index] = 0;
       }
}
pixelDataElement.Value = pixelArrayBuffer; 
DicomDict.dict['7FE00010'] = pixelDataElement;
new_file_WriterBuffer = DicomDict.write();

Any input or help will be really appreciated. Thanks.

pieper commented 6 months ago

Related to #375. This would also require use of codecs to handle the transfer syntaxes.