dicomParser
dicomParser copied to clipboard
How to solve dicomParser.explicitElementToString: cannot convert implicit element to string?
In the Example of displaying a DICOM P10 from the local file system
I can load the dicom file.
But in my one, I get the below error:
Here is my code: the error happens in 17 line
Can anyone help me to figure out this? Thanks so much!
Since the file you're trying to convert is in implicit VR transfer syntax, dicomParser doesn't know the types of any of its elements. You can make a callback that returns the VR given a tag and pass it to dicomParser.parseDicom in the vrCallback property of the options object (see the README for details). The VRs for all known tags are available here.
Hi @yagni, Thanks so much for your help! However, I still feel a little bit confused about how to implement vrCallback in dicomParser.parseDicom. Does that mean after we add the callback function, we can get a normal dataset that can be used in dicomParser.explicitDataSetToJS(dataSet)?
Below are some of my ideas:
var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);
const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
vrCallback(tag) {
// x00280011 is diocm image width
if (tag=="x00280011"){
return {'tag': '(0028,0011)', 'vr': 'US', 'vm': '1', 'name': 'Columns'}
}
},
});
let tags = dicomParser.explicitDataSetToJS(dataSet);
console.log(tags["x00280011"]);
But when I run the code like this, I still get the same error.
Could you give an example of how to figure out this issue?
You're almost there, but you want to return just the vr ('US' in your example) from the callback. Also, because there are so many tags, I'd recommend something like the following to use the dictionary I mentioned above--that way you don't have to add every tag you use to the callback (they're already there). Assuming you've pasted that TAG_DICT somewhere:
var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);
const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
vrCallback(tag) {
const formatted = `(${tag.substr(1, 4)},${tag.substr(5,9)})`;
return !!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined;
},
});
let tags = dicomParser.explicitDataSetToJS(dataSet);
console.log(tags["x00280011"]);
Hi @yagni,
I followed your advice and copied TAG_DICT file in my project.
then I did the same code as you provide above, but we still get the same issue. Because in the dataset there is still some elements that miss vr attribute.
yes, we can get almost vrs via TAG_DICT[formatted].vr
,
But the result (I console.log(dataset)) is the same as if I had not used the vrCallback option. That means the vrs we haven't returned to the dataset. here are both datasets I logged:
-
without using vrCallback(tag):
-
using vrCallback(tag):
I guess if I correctly returned the vrs, it must be shown in the dataset and with vr attribute in each element, right?
Do you know what's wrong here?
- here is my code:
import { TAG_DICT } from "../lib/dicom_pharser_dictionary";
var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);
// const dataSet1 = dicomParser.parseDicom(dicomFileAsBuffer);
// console.log(dataSet1);
const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
vrCallback(tag) {
const formatted = `(${tag.substring(1, 5)},${tag.substring(5, 9)})`;
// console.log(!!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined);
return !!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined;
},
});
let tags = dicomParser.explicitDataSetToJS(dataSet);
console.log(tags["x00280011"]);
And here is the Dicom file I used.
Thanks so much!
@LinkunGao After digging in the code, it looks like I only ever hooked up the VR callback to sequence parsing, not every implicit element. I'll get a PR through in the next week or so to fix this.
@LinkunGao Please try with the latest release--this should work much better. The explicitDataSetToJs and explicitDataSetToJson examples have been updated with code similar to what we talked about. I also realized the tag needed to be upper cased:
const formatted = `(${tag.substr(1, 4).toUpperCase()},${tag.substr(5,9).toUpperCase()})`;