[Insight-users] Re sampleImageFilter and multithreading.
Pete79
pkoniusz at hotmail.com
Sat Oct 17 19:56:04 EDT 2009
Dear all.
I'm running multiple threads which launch a subroutine which consists of the
following:
- RegionOfInterestImageFilter
- ResampleImageFilter
- LinearInterpolateImageFunction
- AffineTransform
As one can imagine, the main class has got an input image stored, and a
number ot threads are launched with _beginthread. Bounding boxes are the
data passed through and then region of interest is extracted and an affine
transform applied through resampling process.
The issue I'm encountering is the following. Some of affine transformed ROIs
are just blank. It happens by a random chance. If I process let's say 400
bounding boxes (ROIs), sometimes all 400 are processed correctly, on the
other occasion only first batch of let's say 38 is actually processed
correctly.
Now, I've made sure that thread launching/finishing is synchronised with
exiting, to wit: before the main thread exits, it waits for all ROIs to get
process and for all threads to finish. Basically, it all uses critical
section for reading/writing from/to flags, so I'm pretty sure there are no
races.
My question is, whether there are any issues with ResampleImageFilter
concerning its application in multithreading environments (every thread
allocates its own new instance of this class)? I'm pretty sure that ROI
filter works fine as I can always store its output before exiting each
thread. Though, resampling seems to work by random chance basically. I set
up number of internal ROI and resample filter threads to 1 by
SetNumberOfThreads(1) to make sure it doesn't interfere with my multithread
approach. Also, if I replace _beginthread and call a thread subroutine
n-times consecutively, all works perfectly fine. Basically, it looks like
there is something going on in resample filter that I don't fully get while
running it from a batch of separate threads managed by myself. Basically, my
first thoughts are that an output smart pointer somewhere in the code ceases
existing way to early as opposed to what is expected by its scope.
A simple example of how I deal with the image flow:
ProcessSegmentsThread(void *pParamC)
{
-get bounding boxes and pointers to source images (exist throughout life of
a mother class)
-signalises to a host subroutine that all input data is being now copied
locally
- smart pointer to ROI roi_img;
- smart pointer to Resampled res-img;
ProcessfSegmentsAffine(input_img, ROI, &roi_img, &res_img);
- store images
- signalise to the host subroutine the thread ends
}
ProcessPairsOfSegmentsAffine(image* input, (smart_ptr_to_roi)* ppROI,
(smart_ptr_to_res)* ppRes)
{
- create ROI filter
roif->SetInput(input);
roif->Update();
if (ppROI) *ppROI=roif->GetOutput(); %smart pointer copied to a smart
pointer existing in outer scope!
- create resample filter
resamp->SetInput(roif->GetOutput())
- set up parameters of affine transform, etc.
if (ppRes) *ppRes=resampl->GetOutput();
}
I reckon I'm using ITK 3.6 as far as I remember correctly. This all is set
up in MSVC 2008 x64 and Windows XP x64.
Any ideas?
--
View this message in context: http://www.nabble.com/ResampleImageFilter-and-multithreading.-tp25942385p25942385.html
Sent from the ITK - Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list