Hi there,
I am trying to get access to the pixel data of individual frames in Multi-frame DICOM file.
I am using the following code:
DicomImage** ImgArr;
......
......
for ( int fi=0; fi<NumFrames; fi++ ) {
ImgArr[fi] = new DicomImage((DcmObject*)dataset,Tsyntax,0,unsigned long(fi),unsigned long(1));
}
All is working as expected in serial mode as above.
My file is very large (3680 frames) so it takes long time. So if I try to parallelize it, like this:
parallel_for(size_t(0), size_t(NumFrames), size_t(1), [=](size_t fi ) {
ImgArr[fi] = new DicomImage((DcmObject*)dataset,Tsyntax,0,unsigned long(fi),unsigned long(1));
});
Is this a known "feature"? Is there a workaround?
Thank you in advance.
DicomImage() constructor is NOT thread safe
Moderator: Moderator Team
-
- Posts: 32
- Joined: Mon, 2018-11-12, 20:01
-
- OFFIS DICOM Team
- Posts: 1445
- Joined: Tue, 2004-11-02, 17:22
- Location: Oldenburg, Germany
- Contact:
Re: DicomImage() constructor is NOT thread safe
The problem is that you pass the same DcmDataset object to all constructors, which is not supported. DcmDataset loads larger attribute values from the file in a lazy "on demand" pattern when they are accessed first. Probably all of your constructors trigger this behaviour in parallel. It might help to call dataset->loadAllDataIntoMemory() before creating the DicomImage instances. This causes the complete dataset (including the pixel data) to be read into main memory. Then you should probably create the first DicomImage instance serially, which will cause the byte order in the loaded data to be adjusted to the CPU byte order (this also only happens at first access). After that, perhaps creating further DicomImage instances for the remaining frames might work in parallel, but I can't guarantee that.
Who is online
Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 1 guest