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

dave common8 at gmail.com
Mon Aug 6 15:15:01 EDT 2007


Not sure if this went through, sorry if two show up.

---------- Forwarded message ----------
From: dave <common8 at gmail.com>
Date: Aug 6, 2007 3:08 PM
Subject: Re: Getting started with a neighborhood operator
To: insight-users at itk.org

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> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070806/7cd08ca0/attachment-0001.html


More information about the Insight-users mailing list