[Insight-users] One last call for help - neighborhood operator

Daniel Mace dlm19 at duke.edu
Wed Aug 22 19:30:21 EDT 2007


Dave,

Don't copy everything over from the iterator into a separate 
vector/matrix for processing.  I had a similar situation with coding up 
a conditional random field for classifying texture patterns, and after 
spending some time profiling the code I found that one of my main bottle 
necks was in the overhead of filing and passing the neighborhood 
matrix.  It's easier and more efficient to grab the iterator over the 
neighborhood elements and extend your calculator to accept the begin and 
end iterators over the neighborhood.

I don't have my code in front of me right now, but I'm pretty sure you 
can just grab the neighborhood iterator after you you get the 
neighborhood element


-----------------------------

	//  Manually update the temp image (this was a last resort because
	//     the NeighborhoodIterator does not seem to support passing
	//     the current neighborhood as an image directly)
	//  This should be fixed for general neighborhood sizes and 
	//     generalized image dimensions!!
	NeighborhoodIteratorType::NeighborhoodType neighborhood = it.GetNeighborhood();

              

	NeighborhoodIteratorType::NeighborhoodType::ConstIterator beginNeighborhood = neighborhood.Begin();
	NeighborhoodIteratorType::NeighborhoodType::ConstIterator endNeighborhood = neighborhood.End();

	MyFunctionToCalculateNeighborhoodStatistics(beginNeighborhood,endNeighborhood);

----------------------------

Something along those lines (I had to rewrite the NeighborhoodIterator to iterate over the elements in a different order, so mine was a bit different, but I think this should work).

It will probably be cleaner to move all the iterating over the neighborhood into its own separate filter (perhaps collapse this into your own class that extends 
itk::Statistics::ScalarImageTextureCalculator, so all the iterating and sample means are calculated quickly and with little overhead), and return whatever elements you need for further classifying.

Cheers,
Dan 


dave wrote:
> Hello all,
>
> I am still trying to get something to work with my neighborhood iterator.
>
> Quick rehash: I want to extract many small neighborhoods (just 2D 
> boxes) of values from an input image.  I am using a texture calculator 
> that calculates textural characteristics from an input image, so I 
> need the neighborhood iterator to send an itk::Image to the calculator.
>
> However, the only way I see to do this is to Get the current 
> iterator's neighborhood, and manually copy each pixel into a tempImage 
> that I send to the calculator.  This is quite slow and since I have to 
> manually define each index I need to copy, it is not generalized to an 
> arbitrarily sized "box" of values.
>
> Is there a way to get an itk::Image directly from the iterator's 
> current neighborhood?
>
> Again, thanks for any help.
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>   



More information about the Insight-users mailing list