[Insight-users] Re sampleImageFilter and multithreading.
Luis Ibanez
luis.ibanez at kitware.com
Sat Oct 17 20:45:06 EDT 2009
Hi Pete79,
Thanks for the detailed description of the problem.
1) Did you enable ITK_USE_REVIEW in CMake ?
2) Did you enable ITK_USE_OPTIMIZED_REGISTRATION_METHODS in CMake ?
Depending on this, you will be using the
itkResampleImageFilter class in
Insight/Code/BasicFilters
or the more recent version of
itkOptResampleImageFilter in
Insight/Code/Review
3) Are you reusing the instances of the filter in any way ?
or are each one of the instances used in an independent
thread and then discarded ?
4) Something that may be confusing the behavior of the
filter, is that the filter by itself tries to split its job into
multiple threads, but at the same time you may have
use a large number of thread for running each individual
filter.
I would suggest to set each instance of the filter to
use only one thread. In that way your management of
the threads will not interfere with what the filters attempt
to do internally.
Try calling SetNumberOfThreads(1) on all the instances
of the Resample filter, before you call Update on them.
Please let us know what you find,
Thanks
Luis
---------------------------------------------------------------------------------------------
On Sat, Oct 17, 2009 at 7:56 PM, Pete79 <pkoniusz at hotmail.com> wrote:
>
> 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.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list