View in #cornerstone3d on Slack
@Leo_Reubelt: i have a viewer using Cornerstone. i use a custom image loader and metadata provider to load the images from aws medical imaging. but i also have to use the viewer with unprocessed files in memory for preview purposes. so i made a different image loader and metadata provider to handle that.
i use https://github.com/cornerstonejs/dicomParser to parse the file and get the datasets. and use the following to decode the pixel data…
const pixelDataElement = dataSet.elements.x7fe00010;
const byteArray = new Uint8Array(
dataSet.byteArray.buffer,
pixelDataElement.dataOffset,
pixelDataElement.length,
);
const transferSyntax = getValueForTag(DicomTag.TRANSFER_SYNTAX_UID, dataSet);
//'@cornerstonejs/dicom-image-loader'
const decodedImageFrame = await dicomImageLoader.decodeImageFrame(
{
...cornerstoneImageFrame,
},
transferSyntax,
byteArray,
undefined,
{
preScale: {
enabled: true,
scalingParameters: {
rescaleIntercept: cornerstoneImageFrame.rescaleIntercept,
rescaleSlope: cornerstoneImageFrame.rescaleSlope,
modality: cornerstoneImageFrame.modality,
},
},
},
);
and some files work, but others do not.
i have one that throws the following two errors
Malformed JP2 file format: first box must be JPEG 2000 signature box
opj_decompress: failed to read the header
any idea what is causing these errors? is there something else i have to do to the byte array to avoid this?
cornerstonejs/dicomParser
@Bill_Wallace: Have you tried that in the vanilla OHIF viewer or modify an example in CS3D to try viewing?
I suspect the issue is that you have DICOM conformant JPEG 2000 files, and the codec doesn’t actually handle fully conformant JPEG 2000 encoding because it is asking for the JPEG 2000 box format, whereas the DICOM standard specifies the the box format is not permitted.
@Leo_Reubelt: thanks @Bill_Wallace. I did try it in ohif. it did load.
@Bill_Wallace: Hmm, that is odd. It suggests it got returned as something other than JPEG 2000, but you are trying to decode it as JPEG 2000. Hmm, that might be in the HTJ2K decoder - the AWS data is coming back in HTJ2K, NOT in JPEG 2000. Can you check which decoder is attempting to decode it?
@Leo_Reubelt: i will. but this is not aws data. it is the raw file before it is processed by aws
@Bill_Wallace: Then you need to know the original transfer syntax uid, and it has to match what the image encoding was used that you are trying to decode.
@Leo_Reubelt: 1.2.840.10008.1.2.4.90
@Bill_Wallace: In the HTTP response header for the image, take a look at what transfer syntax it says it is - that is available in the body for the response, as it is encoded in multipart/related. Or, if it is a raw image, check what the raw image data is.
That is JPEG 2000, but you need to know the actual image format - that error says it isn’t JPEG 2000
@Leo_Reubelt: ok. understood.