Describe Your Question
- I am trying to provide a custom image loader and am struggling to do so.
Any advice or help would be lovely. I believe they’re being loaded in but not displayed on the viewport. I am trying to move away from the cornerstoneWADOImageLoader as it is deprecated and is failing to load some of my dicom files that other systems can load.
The base64 that is returned is of the entire .dcm file.
component.library_load.dicom.image_loader_ = function(imageId) {
console.log('imageId', imageId);
const key = imageId.split(':')[1];
console.log('window.dicomParser', window.dicomParser);
let xhr = null;
const cancelFn = () => {
if (xhr) {
xhr.abort();
console.log('Aborting request');
}
};
const promise = new Promise((resolve, reject) => {
xhr = api('<server>', 'get_contents_base64', key, function(base64) {
try {
const canvas = document.createElement('canvas');
const binary = atob(base64);
const byteArray = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
byteArray[i] = binary.charCodeAt(i);
}
const dicomParser = window.dicomParser;
const dataSet = dicomParser.parseDicom(byteArray);
const pixelDataElement = dataSet.elements.x7fe00010;
const pixelData = new Uint8Array(dataSet.byteArray.buffer, pixelDataElement.dataOffset, pixelDataElement.length);
const img = {
'imageId': imageId,
'minPixelValue': 0,
'maxPixelValue': 255,
'slope': 1,
'intercept': 0,
'windowCenter': 128,
'windowWidth': 255,
'getPixelData': function() {
return pixelData;
},
'getCanvas': function() {
return canvas;
},
'rows': dataSet.uint16('x00280010'),
'columns': dataSet.uint16('x00280011'),
'height': dataSet.uint16('x00280010'),
'width': dataSet.uint16('x00280011'),
'color': false,
'rgba': false,
'numComps': 1,
'columnPixelSpacing': dataSet.float('x00280030'),
'rowPixelSpacing': dataSet.float('x00280030'),
'sliceThickness': dataSet.float('x00180050'),
'invert': false,
'sizeInBytes': pixelData.length,
'data': dataSet,
};
console.log('image', img);
resolve(img);
} catch (error) {
reject(error);
}
}, xhr);
});
return {
promise,
cancelFn,
};
};