Request: Better Documentation for Writing DICOM Files
Request: Better Documentation for Writing DICOM Files
Hello! Thank you for maintaining dcmjs. It's a really useful library for working with DICOM in JavaScript.
However, the documentation for creating DICOM files (especially from scratch ) is very limited and difficult to follow for new users. It’s unclear what the expected structure of the dataset should be, or how to correctly handle PixelData and metadata like Rows, Columns, BitsAllocated, etc.
Problem Areas:
- No clear example of how to build a valid dataset for writing a new
.dcmfile - Missing explanation of
naturalizeDataset,denaturalizeDataset, and when to use each - Lack of typing or reference for what a valid DICOM dictionary structure looks like
- No guide for writing multi-frame or image-based DICOMs (e.g., Ultrasound, CT)
Request:
Could you please add:
- A section in the README for writing/exporting DICOM
- A full working example of writing a DICOM image (single-frame and optionally multi-frame)
- Explanation of the required tags and structure (
SOPClassUID,PixelRepresentation, etc.)
Thanks again for your work! I’d be happy to help test or contribute examples if needed.
Thanks for the feedback 👍
Yes, dcmjs is a community project with lots of possible uses and very little direct support, so most progress is made when developers need new features for their own work.
Thanks again for your work! I’d be happy to help test or contribute examples if needed.
This would be much appreciated!
I recently had a need to create a part10 binary from scratch so I adapted this from the tests:
https://github.com/bebbi/simpleDevDcm/blob/main/src/index.html#L313-L349
It would be great if you want to flesh it out with real image and metadata into an example.
Also the demos are broken (and minimal) in case can chip in to work on those.
@pieper Thank you for your response. However, the link you provided leads to a 404 error.
Sorry, I guess that repo is private.
Here's the code in question:
const dataset = {
'00080008': { vr: 'CS', Value: ['DERIVED'] },
'00082112': {
vr: 'SQ',
Value: [
{ '00081150': { vr: 'UI', Value: ['1.2.840.10008.5.1.4.1.1.7'] } },
],
},
'00180050': { vr: 'DS', Value: [1] },
'00181708': { vr: 'IS', Value: [426] },
'00189328': { vr: 'FD', Value: [30.98] },
'0020000D': {
vr: 'UI',
Value: [
'1.3.6.1.4.1.5962.99.1.2280943358.716200484.1363785608958.3.0',
],
},
'00400254': { vr: 'LO', Value: ['DUCTO/GALACTOGRAM 1 DUCT LT'] },
'7FE00010': { vr: 'OW', Value: [new Uint8Array([0x00, 0x00]).buffer] },
}
const dicomDict = new dcmjs.data.DicomDict({})
dicomDict.dict = dataset
const dicomArrayBuffer = dicomDict.write()
const reparsedDicomDict =
dcmjs.data.DicomMessage.readFile(dicomArrayBuffer)
const dicomBlob = new Blob([dicomArrayBuffer], {
type: 'application/octet-stream',
})
const naturalDataset =
dcmjs.data.DicomMetaDictionary.naturalizeDataset(dataset)
console.log(dicomDict)
console.log(dicomArrayBuffer)
console.log(reparsedDicomDict)
console.log(dicomBlob)
console.log(JSON.stringify(naturalDataset))