[Insight-users] Re: Getting started with a neighborhood operator

Luis Ibanez luis.ibanez at kitware.com
Fri Aug 10 10:24:18 EDT 2007


Hi Dave,

Why do you want to treat the group of pixels in the neighborhood
as a "full image object" ?

Maybe it will be helpful to start from the beginning and share
with us a bit of background regarding what you are actually trying
to compute from your input image.

Using a neighborhood as a full-image looks like an overkill.
Is very likely that there are better ways of implementing the
process that you are interested on.


   Please let us know,


      Thanks


        Luis


--------------
dave wrote:
> Hello again
> 
> To be more specific, I don't know how to grab the current neighborhood 
> as an image from the NeighborhoodIterator.  My code is below.  The 
> problem I am having is that the texture calculator keeps returning the 
> same feature values (energy, entropy) for all supposed neighborhoods.  
> If I use different input image files, the feature values are different, 
> so it does seem that the calculator is getting something from the file, 
> but the "block" doesn't seem to update after the first iteration.  Do I 
> need to actually take the neighborhood pixel values, one by one, and 
> place them in my temp image each time? (I'm hoping no since the reason 
> I'm using ITK is so I can have generalized code)
> 
> Again, thanks for any help someone can provide
> 
> 
> 
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
> 
> #include "itkImageFileReader.h"
> #include "itkNeighborhoodIterator.h"
> #include "itkScalarImageToGreyLevelCooccurrenceMatrixGenerator.h"
> #include "itkGreyLevelCooccurrenceMatrixTextureCoefficientsCalculator.h"
> 
> 
> int main( int argc, char * argv [] )
> {
>   if( argc < 2 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0];
>     std::cerr << " inputScalarImage" << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   const char * inputImageFileName = argv[1];
> 
>   typedef char          InputPixelType;
>   const unsigned int    Dimension = 2;
> 
>   typedef itk::Image<InputPixelType, Dimension > InputImageType;
>   typedef itk::ImageFileReader< InputImageType > ReaderType;
>   typedef itk::NeighborhoodIterator< InputImageType > 
> NeighborhoodIteratorType;
>   typedef 
> itk::Statistics::ScalarImageToGreyLevelCooccurrenceMatrixGenerator<
>       InputImageType> GLCMGenType;
>   typedef 
> itk::Statistics::GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator<
>       GLCMGenType::HistogramType > TexCalcType; 
> 
>   //  Read input image
>   ReaderType::Pointer reader = ReaderType::New();
>   reader->SetFileName( inputImageFileName );
>   try
>     {
>     reader->Update();
>     }
>   catch( itk::ExceptionObject & err )
>     {
>     std::cerr << "ExceptionObject caught !" << std::endl;
>     std::cerr << err << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   //  Set up neighborhood iterator and the temp output image, "block"
>   NeighborhoodIteratorType::RadiusType radius;
>   radius.Fill(1);
>   NeighborhoodIteratorType it( radius, reader->GetOutput(),
>                     reader->GetOutput()->GetRequestedRegion() );
>   InputImageType::Pointer block = InputImageType::New();
>   block->SetRegions( it.GetRegion());
>   block->Allocate();
>   block->Print( std::cout );
> 
>   //  Set up GLCM
>   GLCMGenType::Pointer glcm = GLCMGenType::New();
>   glcm->SetInput( block );
>   InputImageType::OffsetType offset = {1,1};
>   glcm->SetOffset( offset ); 
>   glcm->Compute();
> 
>   //  Set up texture calculator
>   GLCMGenType::HistogramType::Pointer hist = glcm->GetOutput();
>   TexCalcType::Pointer texCalc = TexCalcType::New();
>   texCalc->SetHistogram( hist );
> 
> 
>   for (it.GoToBegin() ; !it.IsAtEnd(); ++it)
>     {
> 
>     //  Update GLCM
>     try
>         {
>         glcm->Compute();
>         }
>     catch( itk::ExceptionObject & err )
>         {
>         std::cerr << "ExceptionObject caught !" << std::endl;
>         std::cerr << err << std::endl;
>         return EXIT_FAILURE;
>         }
> 
> 
>     // Calculate Textural Information from GLCM
>     try
>         {
>         texCalc->Compute();
>         }
>     catch( itk::ExceptionObject & err )
>         {
>         std::cerr << "ExceptionObject caught !" << std::endl;
>         std::cerr << err << std::endl;
>         return EXIT_FAILURE;
>         }
> 
> 
>     //  Output (testing)
>     std::cout << "Center Pixel Index = " << it.GetIndex() << std::endl;
>     InputImageType::PixelType value = it.GetCenterPixel();
>     std::cout << "   Center Pixel value = " << value << std::endl;
>     std::cout << "   Energy = " << texCalc->GetEnergy() << std::endl;
>     std::cout << "   Entropy = " << texCalc->GetEntropy() << std::endl;
>     }
> 
>   return EXIT_SUCCESS;
> }
> 
> 
> 
> On 8/6/07, dave <common8 at gmail.com <mailto:common8 at gmail.com>> wrote:
>>  I am trying to use a neighborhood operator.  I would like to extract a 
> small (say 3x3 or 5x5) region, and then pass the output image to the 
> ScalarImageToGreyLevelCooccurr enceMatrixGenerator for textural feature 
> extraction. Then, increment the iterator and repeat the process.
>>
>>  Looking at the software guide and the dox, I see that the 
> NeighborhoodIterator has functions for accessing individual pixel 
> values, but how do I setup a small output image that can be updated and 
> used at each iteration? I suppose what I really want to do is just feed 
> the iterator "output image" to the GLCMGenerator but I can't seem to 
> find the correct way to do it.
>>
>>  Forgive me if this is something really simple, and thanks
>>  Dave
>>
>>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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