[Insight-users] Re sampleImageFilter and ITK_USE_OPTIMIZED_REGISTRATION_METHODS

Pete79 pkoniusz at hotmail.com
Thu Oct 22 15:54:35 EDT 2009


Luis, hi.


Luis Ibanez wrote:
> 
> The Resample image filter already knows how to distribute
> its load over multiple threads.  There is no benefit in you
> trying to do that distribution manually.
> 

There is a benefit in a way I'm also using a bunch of my own subroutines
that perform heavy computations after affine transforms of let's say 2000
regions per image are completed. Therefore, I do prefer to keep a local
affine transformed image object in each thread and further feed it to my
subroutines rather than process sequentially (although with multithreading)
all regions, keep pointers to 2000 images and then pass them to my custom
threads when launched ... if you get my drift.



> You can easily verify this by running any of the many
> examples in the directory:
> 

Thanks, I am really familiar with them by now, though there is nothing
challenging about the whole case. I know that when images are large, it can
basically split the load into multiple jobs.



> Please let us know what you find.
> 

This may be the most startling, but it looks I've tracked down the bug that
was sporadically happening -  let's say once a 1000 files processed. I
cannot vouch I'm 100% sure my code is bug-free, but I was fiddling and
testing behaviour of the code on a large dataset to be sure that I can
reproduce these crashes, and ...

when I chucked out RegionOfInterestImageFilter and replaced it with my
custom code, all problems disappeared finally (at least I cannot spot
nothing wrong at the moment).

The code in the custom thread subroutine used to be as follows:

	// <== for picking up a desired ROI
	ITKLabROIFSPT pfROIOfLabsIm=ITKLabROIFT::New();
	ITKOrigBWROIFSPT pfROIOfOrigBWIm=ITKOrigBWROIFT::New();

	// <== inputs of ROI filters are set up for every instance of a filter
	pfROIOfLabsIm->SetInput(piLabsInC);
	pfROIOfOrigBWIm->SetInput(piOrigBWC);

	// <== sets up ROI of a ROI filter
	pfROIOfLabsIm->SetRegionOfInterest(xRegPairOfSegs);
	pfROIOfOrigBWIm->SetRegionOfInterest(xRegPairOfSegs);

	pfROIOfLabsIm->SetNumberOfThreads(1);
	pfROIOfOrigBWIm->SetNumberOfThreads(1);

	pfROIOfLabsIm->Update();
	pfROIOfOrigBWIm->Update();

I've made sure I wasn't requesting a region outside of image dimensions, but
it still kept crashing once a blue moon when launched in a thread (even when
it was left out solely alone in the thread code).

I just replaced it with:
	// <== for picking up desired ROI 
	ITKLabsInImSPT piROIOfLabsIm;
	CloneImage<ITKLabsInImT, ITKLabsInImT>(piLabsInC, xRegPairOfSegs,
piROIOfLabsIm);

	ITKOrigBWImSPT piROIOfOrigBWIm;
	CloneImage<ITKOrigBWImT, ITKOrigBWImT>(piOrigBWC, xRegPairOfSegs,
piROIOfOrigBWIm);


And the CloneImage is defined more or less as the following:
	NewImage<ITKOutputImT>(rpiOutputImC, rxRegInputImC);

	ITKInputImItT itITKInputIm_i(piInputImC, rxRegInputImC);
	ITKOutputImItT itITKOutputIm_i(rpiOutputImC, rxRegInputImC);

	for (itITKInputIm_i.GoToBegin(), itITKOutputIm_i.GoToBegin();
		 !itITKInputIm_i.IsAtEnd(); ++itITKInputIm_i, ++itITKOutputIm_i)
			itITKOutputIm_i.Set(itITKInputIm_i.Get());

It allocates desired ROI image and links with a smart pointer, sets up a ROI
for iterator which copies from a source to destination.



More information about the Insight-users mailing list