<div dir="ltr">Hi Bradley, thank for your response. I have already check the itk module you send me, in fact I use it as a reference to create my own, yours and mine basically do the same. I will try to use yours in the same 3D image and see if there is any problem similar to mine.<div>
<br></div><div>Thanks a lot.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 19, 2013 at 8:31 PM, Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am not entirely sure what your filter is trying to do, nor what&#39;s the problem you are encountering.<br>
<br>
I have an itk module which has a filter to compute the GLCM for a neighborhood around each pixel. This may be what you are looking for, or at least give you some ideas on how to use the components.<br>
<br>
As it has been a while since I last used this filter, and there is a lack of rigorous testing, I&#39;d recommend writing a test to verify the results for your usage before relaying on the output.<br>
<br>
Good luck,<br>
Brad<br>
<br>
[1] <a href="https://github.com/blowekamp/itkTextureAnalysis/blob/master/include/itkTextureFeatureImageFilter.h" target="_blank">https://github.com/blowekamp/itkTextureAnalysis/blob/master/include/itkTextureFeatureImageFilter.h</a><br>

<div><div class="h5"><br>
On Aug 19, 2013, at 8:46 PM, Fabian Torres &lt;<a href="mailto:dae.wong@gmail.com">dae.wong@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Hi all. I am trying to implement a filter that gives local texture analysis. For this I implement a itkImagetoImageFilter that calculates coocurrence texture descriptor for each pixel using itkScalarImageToCoocurrenceMatrizFilter.<br>

&gt;<br>
&gt; I know this is a slow implementation, but the real problem I have is that when I try to use this with a 3D image, even a small one of 43x35x61, the computer runs out of memory. I do not know if I my implementation is wrong. But it seems that for each pixel I´m using a lot of memory.<br>

&gt;<br>
&gt; I hope someone can help me with this. Here I leave the code for the GenerateData() function.<br>
&gt;<br>
&gt; Thanks.<br>
&gt;<br>
&gt; this-&gt;AllocateOutputs();<br>
&gt;<br>
&gt;  ProgressReporter progress( this, 0,<br>
&gt;        this-&gt;GetInput()-&gt;GetRequestedRegion().GetNumberOfPixels(), 100 );<br>
&gt;<br>
&gt;  typedef MirrorPadImageFilter&lt;InputImageType,InputImageType&gt; PadFilterType;<br>
&gt;  typename PadFilterType::Pointer padFilter = PadFilterType::New();<br>
&gt;<br>
&gt;  int boundSize = floor(this-&gt;m_RegionSize[1]/2);<br>
&gt;<br>
&gt;  RegionSizeType bound;<br>
&gt;  bound.Fill(boundSize);<br>
&gt;<br>
&gt;  padFilter-&gt;SetPadBound(bound);<br>
&gt;  padFilter-&gt;SetInput(this-&gt;GetInput());<br>
&gt;  padFilter-&gt;Update();<br>
&gt;<br>
&gt;  typename InputImageType::Pointer padImage = padFilter-&gt;GetOutput();<br>
&gt;<br>
&gt;  typedef Statistics::ScalarImageToCooccurrenceMatrixFilter&lt;InputImageType&gt;<br>
&gt;          GLCMGeneratorType;<br>
&gt;  typename GLCMGeneratorType::Pointer glcmGenerator = GLCMGeneratorType::New();<br>
&gt;<br>
&gt;  glcmGenerator-&gt;SetNumberOfBinsPerAxis(this-&gt;m_NumberofBins);<br>
&gt;  glcmGenerator-&gt;SetPixelValueMinMax(this-&gt;m_PixelMinValue,m_PixelMaxValue);<br>
&gt;<br>
&gt;  typedef typename InputImageType::OffsetType OffsetType;<br>
&gt;<br>
&gt;  OffsetType offset1;<br>
&gt;  offset1[0] = 1;<br>
&gt;  offset1[1] = 0;<br>
&gt;<br>
&gt;  OffsetType offset2;<br>
&gt;  offset2[0] = 1;<br>
&gt;  offset2[1] = -1;<br>
&gt;<br>
&gt;  OffsetType offset3;<br>
&gt;  offset3[0] = 0;<br>
&gt;  offset3[1] = -1;<br>
&gt;<br>
&gt;  OffsetType offset4;<br>
&gt;  offset4[0] = -1;<br>
&gt;  offset4[1] = -1;<br>
&gt;<br>
&gt;  typedef typename GLCMGeneratorType::OffsetVector OffsetVectorType;<br>
&gt;  typename OffsetVectorType::Pointer offsets = OffsetVectorType::New();<br>
&gt;<br>
&gt;  offsets-&gt;reserve(4);<br>
&gt;  offsets-&gt;InsertElement(0,offset1);<br>
&gt;  offsets-&gt;InsertElement(1,offset2);<br>
&gt;  offsets-&gt;InsertElement(2,offset3);<br>
&gt;  offsets-&gt;InsertElement(3,offset4);<br>
&gt;<br>
&gt;  glcmGenerator-&gt;SetOffsets(offsets);<br>
&gt;<br>
&gt;  typedef typename GLCMGeneratorType::HistogramType HistogramType;<br>
&gt;  typedef Statistics::HistogramToTextureFeaturesFilter&lt;HistogramType&gt;<br>
&gt;          TextureFeaturesType;<br>
&gt;  typename TextureFeaturesType::Pointer textureFeatures;<br>
&gt;<br>
&gt;  if(this-&gt;m_TextureFeature&lt;=8 &amp;&amp; this-&gt;m_TextureFeature&gt;=0){<br>
&gt;      textureFeatures = TextureFeaturesType::New();<br>
&gt;  }else{<br>
&gt;      textureFeatures = NULL;<br>
&gt;  }<br>
&gt;<br>
&gt;  typedef ExtractImageFilter&lt;InputImageType,InputImageType&gt; ExtractFilterType;<br>
&gt;  typename ExtractFilterType::Pointer extractFilter = ExtractFilterType::New();<br>
&gt;<br>
&gt;  typename InputImageType::RegionType region;<br>
&gt;  typename InputImageType::IndexType regionIndex;<br>
&gt;<br>
&gt;  region.SetSize(this-&gt;m_RegionSize);<br>
&gt;<br>
&gt;  extractFilter-&gt;SetInput(padImage);<br>
&gt;<br>
&gt;  ImageRegionIteratorType itPad(padImage, padImage-&gt;GetLargestPossibleRegion());<br>
&gt;  itPad.GoToBegin();<br>
&gt;<br>
&gt;  ImageRegionIteratorType itOut(this-&gt;GetOutput(),<br>
&gt;          this-&gt;GetOutput()-&gt;GetLargestPossibleRegion());<br>
&gt;  itOut.GoToBegin();<br>
&gt;<br>
&gt;  while(!itPad.IsAtEnd()){<br>
&gt;<br>
&gt;        regionIndex = itPad.GetIndex();<br>
&gt;        region.SetIndex(regionIndex);<br>
&gt;<br>
&gt;        if(padImage-&gt;GetLargestPossibleRegion().IsInside(region)){<br>
&gt;<br>
&gt;            extractFilter-&gt;SetExtractionRegion(region);<br>
&gt;            extractFilter-&gt;UpdateLargestPossibleRegion();<br>
&gt;<br>
&gt;            glcmGenerator-&gt;SetInput(extractFilter-&gt;GetOutput());<br>
&gt;            glcmGenerator-&gt;UpdateLargestPossibleRegion();<br>
&gt;<br>
&gt;            if(this-&gt;m_TextureFeature == 0){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::Energy));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 1){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::Entropy));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 2){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::Correlation));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 3){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::InverseDifferenceMoment));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 4){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::Inertia));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 5){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::ClusterShade));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 6){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::ClusterProminence));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 7){<br>
&gt;                textureFeatures-&gt;SetInput(glcmGenerator-&gt;GetOutput());<br>
&gt;                textureFeatures-&gt;UpdateLargestPossibleRegion();<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),<br>
&gt;                        textureFeatures-&gt;GetFeature(TextureFeaturesType::HaralickCorrelation));<br>
&gt;            }else if(this-&gt;m_TextureFeature == 8){<br>
&gt;<br>
&gt;                typename HistogramType::ConstPointer hist = glcmGenerator-&gt;GetOutput();<br>
&gt;<br>
&gt;                typename HistogramType::ConstIterator it = hist-&gt;Begin();<br>
&gt;<br>
&gt;                float mean = 0;<br>
&gt;                while(it != hist-&gt;End()){<br>
&gt;                    mean += it.GetFrequency();<br>
&gt;                    ++it;<br>
&gt;                }<br>
&gt;<br>
&gt;                float nBins = hist-&gt;GetSize(0);<br>
&gt;                nBins *= nBins;<br>
&gt;<br>
&gt;                mean /= nBins;<br>
&gt;<br>
&gt;                float variance = 0;<br>
&gt;                it = hist-&gt;Begin();<br>
&gt;                while( it != hist-&gt;End()){<br>
&gt;                    variance += pow(it.GetFrequency()-mean,2);<br>
&gt;                    ++it;<br>
&gt;                }<br>
&gt;<br>
&gt;                variance /= (nBins - 1);<br>
&gt;<br>
&gt;                this-&gt;GetOutput()-&gt;SetPixel(itOut.GetIndex(),variance);<br>
&gt;<br>
&gt;                hist = NULL;<br>
&gt;<br>
&gt;            }<br>
&gt;<br>
&gt;            ++itOut;<br>
&gt;<br>
&gt;            progress.CompletedPixel();<br>
&gt;<br>
&gt;        }<br>
&gt;<br>
&gt;        ++itPad;<br>
</div></div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Fabián Torres Robles<br>Maestria en Ciencias en Ingeniería Electrónica<br>Ingeniería en Sistemas Electrónicos<br>tel. 58081280, 0445534661338<br>e-mail <a href="mailto:fabian.trobles@gmail.com" target="_blank">fabian.trobles@gmail.com</a>, <a href="mailto:dae.wong@gmail.com" target="_blank">dae.wong@gmail.com</a>  <div style="padding:0px;margin-left:0px;margin-top:0px;overflow:hidden;word-wrap:break-word;color:black;font-size:10px;text-align:left;line-height:130%">
</div>
</div>