Parse labels in DCM files
The DCM file contains information labels related to the patient and the cause, which may or may not be used, but it is important to know. You can go to this site and check out the tag information DICOM, or the nuggets have been summarized by the author. Link.
Parsing these tags requires the dicomParser plug-in
// In this function some objects are returned, Data attributes of objects and mount the tag information cornerstone. LoadAndCacheImage (imageId). Then (img = > {cornerstone. The displayImage (img element); })Copy the code
img.data
- ByteArray this is an array of bytes
- Properties in byteArrayParser parse raw arrays of data
- Elements Label information in the DCM file
The information corresponding to the tag is not expanded, and the two websites provided have explanations. For example, if you need to get the patient ID –> img.data.elements[“x00100020”], you can get a byte bit containing the beginning and end of the patient ID.
- DataOffset The start bit in an array of bytes
- Length Indicates the length of the patient ID
- ID tag patients
- Vr recognizes data types
Knowing this information, you can use the DataSet constructor provided by dicomParser to parse the tag information, or you can parse it yourself. String.fromcharcode is used for both self parsing and dicomParser parsing. First look at the source code:
The text and string in the DataSet function are roughly the same.
string
text
It’s easy to use
cornerstone.loadAndCacheImage(imageId).then(img => {
let byteArray = img.data.byteArray,
byteArrayParser = img.data.byteArrayParser,
elements = img.data.elements;
console.log(new dicomParser.DataSet(byteArray,byteArrayParser,elements).string("x00100020"));
cornerstone.displayImage(element,img);
})
Copy the code
Self analysis:
let elements = img.data.elements["x00100020"];
resolveTag(img.data.byteArray,elements.dataOffset,elements.length);
function resolveTag(byteArray, position, len) {
let result = "";
for (let i = 0; i < len; i++) {
let temp = byteArray[position + i];
result += String.fromCharCode(temp);
}
return result;
}
Copy the code
Basic can obtain information on these, deeper or rely on their own to view the source code, try to write again.