[Insight-users] Computing Hessian Matrix of Large Image

Bradley Lowekamp blowekamp at mail.nih.gov
Sat Nov 10 20:56:19 EST 2012


Hello Jianxu,

I only have a brief moment to give a couple suggestions. I hope it's enough to get you pointed in the right direction.

ITK's HessianRecursiveGaussianImageFilter is not streamable.

Your streaming pipeline is not correct. You should print the progress of the filters to observe the streaming as the filters are running to know if you have it is correct.

If you are using win64, then make sure you compile ITK with 64BIT IDS, is should be a cmake flag.

I wrote a discrete hessian filter here:

https://github.com/blowekamp/itkLocalDiscreteHessian

You should be able to clone that repository into to ITK's Modules/External/ to build and use it.

Consider using the following pipeline:

ImageReader->SmoothingRecursiveGaussian->DiscreteHessian->Objectness->ImageWriter

To get the pipeline to stream you should be able to just write out to an mha file, and use ImageWriter's SetNumberOfStreamDivisions method.

I advice to begin with a small image and make sure you have a streaming pipeline then work towards the larges.

Good luck, I hope this is enough to get you pointed in the right direction.

Brad

On Nov 10, 2012, at 3:03 PM, Jianxu Chen <jchen16 at nd.edu> wrote:

> Hello Kevin,
> 
> Could you give me a little more details about how to use StreamingImageFilter()? I tried it  with the following code. But the error "Failed to Allocate Memory For Image" still happened. I don't have much experience in ITK. Maybe the streaming filter is employed in an incorrect way.
> 
> The pipeline is ImageReader() --> StreamingFilter() --> HessianFilter() --> HessianToObjectnessFilter() --> ImageWriter()
> 
> Here is part of the code:
> 
> typedef itk::StreamingImageFilter<InputImageType, InputImageType> StreamingFilterType;
> StreamingFilterType::Pointer streaming = StreamingFilterType::New();
> streaming->SetInput(imageReader->GetOutput());
> streaming->SetNumberOfStreamDivisions(8);
> 
> typedef itk::HessianRecursiveGaussianImageFilter< InputImageType > HessianMatrixFilterType;
> HessianMatrixFilterType::Pointer hessianMatrix = HessianMatrixFilterType::New();
> hessianMatrix->SetInput(streaming->GetOutput());
> 
> typedef itk::HessianToObjectnessMeasureImageFilter< HessianMatrixFilterType::OutputImageType,OutputImageType > ObjectnessFilterType;
> ObjectnessFilterType::Pointer objectnessFilter = ObjectnessFilterType::New();
> objectnessFilter->SetInput(hessianMatrix->GetOutput());
> ** Next, Set the parameter for ObjectnessFilter **
> ** Finally, Submit to Image Writer **
> 
> Thanks a lot for your help.
> Jianxu Chen
> 
> 
> On Tue, Nov 6, 2012 at 9:39 AM, Jianxu Chen <jchen16 at nd.edu> wrote:
> Hello Kevin,
> 
> Really appreciate your suggestion. I found that  "SetNumberOfStreamDivisions" is really powerful when handling large data.
> 
> For the Hessian Matrix Filter, I noticed that this problem had already been discussed via the maillist in 2008.
> 
>                    http://www.itk.org/pipermail/insight-users/2008-June/026328.html
> 
> Some tests were conducted there. It showed that it might fail to allocate memory for the Hessian matrix even when there should be enough space theoretically. 
> 
> Anyway, your suggestion of using SetNumberOfStreamDivisions is very useful. My problem can be solved. 
> 
> Thanks again for your help.
> Jianxu Chen
> 
> On Tue, Nov 6, 2012 at 9:26 AM, Kevin H. Hobbs <hobbsk at ohio.edu> wrote:
> On 11/04/2012 03:50 PM, Jianxu Chen wrote:
> > Hello,
> >
> > I encountered a weird problem when computing the Hessian Matrix of a 3D
> > image stack.
> >
> > I used HessianRecursiveGaussianImageFilter to compte the Hessian matrix.
> > However, this filter only works well when the image is very very small.
> >
> > My data is a 1024*1024*30 image stack. When calling
> > HessianRecursiveGaussianImageFilter to calculate the Hessian matrix, the
> > system cannot allocate the memory space for it. Thus, I cut my data into
> > a 350*350*30 image stack. The program works well. My computer has a 8GB
> > RAM and is a 64-bit machine. I am wondering why the system fails to
> > allocate the memory for the filter. There should be enough usable RAM in
> > the machine.
> 
> If your data are unsigned char : 1024*1024*100 / 2^20 = 100 MiB.
> If your data are floats : 1024*1024*100 * 4 / 2^20 = 400 MiB.
> If your data are doubles : 1024*1024*100 * 8 / 2^20 = 800 MiB.
> 
> The Hessian matrix is symmetric so only 6 values are required :
>         1024*1024*100 * 8 * 6 / 2^30 = 4.69 GiB.
> 
> If you have a long pipeline your image could be in memory in many places.
> 
> >
> > My data is at least 1024*1024*30, sometimes even 1024*1024*100. And I
> > have to compute the Hessian matrix in my algorithm. What should I do in
> > this case? Could you give my some advice? Really appreciate your help.
> >
> 
> Shorten your pipeline. Reader => Filter => Writer.
> 
> Set the ReleaseDataFlag or GlobalReleaseDataFlag so that filters free
> their data after satisfying downstream requests.
> 
> Stream your pipeline :
>         writer->SetNumberOfStreamDivisions( n );
> 
> 
> 
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121110/04fdc050/attachment.htm>


More information about the Insight-users mailing list