<span style="font-family: courier new,monospace;">Hello again<br><br>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)
<br><br>Again, thanks for any help someone can provide<br><br><br><br>#if defined(_MSC_VER)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#pragma warning ( disable : 4786 )
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
#include "itkImageFileReader.h"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include "itkNeighborhoodIterator.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkScalarImageToGreyLevelCooccurrenceMatrixGenerator.h"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
#include "itkGreyLevelCooccurrenceMatrixTextureCoefficientsCalculator.h"</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">int main( int argc, char * argv [] )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if( argc < 2 )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cerr << "Usage: " << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << argv[0];
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << " inputScalarImage" << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> const char * inputImageFileName = argv[1];</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef char InputPixelType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> const unsigned int Dimension = 2;
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef itk::Image<InputPixelType, Dimension > InputImageType;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef itk::ImageFileReader< InputImageType > ReaderType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::NeighborhoodIterator< InputImageType > NeighborhoodIteratorType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
typedef itk::Statistics::ScalarImageToGreyLevelCooccurrenceMatrixGenerator<</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> InputImageType> GLCMGenType;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef itk::Statistics::GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator<</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GLCMGenType::HistogramType > TexCalcType; </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
// Read input image</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ReaderType::Pointer reader = ReaderType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> reader->SetFileName( inputImageFileName );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> try</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> reader->Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> catch( itk::ExceptionObject & err )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << "ExceptionObject caught !" << std::endl;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << err << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // Set up neighborhood iterator and the temp output image, "block"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
NeighborhoodIteratorType::RadiusType radius;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> radius.Fill(1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> NeighborhoodIteratorType it( radius, reader->GetOutput(),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> reader->GetOutput()->GetRequestedRegion() );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> InputImageType::Pointer block = InputImageType::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
block->SetRegions( it.GetRegion());</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> block->Allocate();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> block->Print( std::cout );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
// Set up GLCM</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> GLCMGenType::Pointer glcm = GLCMGenType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> glcm->SetInput( block );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> InputImageType::OffsetType offset = {1,1};
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> glcm->SetOffset( offset ); </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
glcm->Compute();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Set up texture calculator</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GLCMGenType::HistogramType::Pointer hist = glcm->GetOutput();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
TexCalcType::Pointer texCalc = TexCalcType::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> texCalc->SetHistogram( hist );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for (it.GoToBegin() ; !it.IsAtEnd(); ++it)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Update GLCM
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> try</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> glcm->Compute();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> catch( itk::ExceptionObject & err )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << "ExceptionObject caught !" << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cerr << err << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return EXIT_FAILURE;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // Calculate Textural Information from GLCM</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> try</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> texCalc->Compute();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> catch( itk::ExceptionObject & err )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << "ExceptionObject caught !" << std::endl;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << err << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Output (testing)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
std::cout << "Center Pixel Index = " << it.GetIndex() << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> InputImageType::PixelType value =
it.GetCenterPixel();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cout << " Center Pixel value = " << value << std::endl;</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cout << " Energy = " << texCalc->GetEnergy() << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cout << " Entropy = " << texCalc->GetEntropy() << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return EXIT_SUCCESS;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">On 8/6/07, dave <<a href="mailto:common8@gmail.com">common8@gmail.com</a>> wrote:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
> 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</span><span style="font-family: courier new,monospace;">
enceMatrixGenerator for textural feature extraction. Then, increment the iterator and repeat the process. </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">> </span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">> 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.
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">> Forgive me if this is something really simple, and thanks
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">> Dave</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">> </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">