[Insight-users] Problem computing coocurence matrix
Christophe Lay
Christophe.Lay at stage.cnes.fr
Wed May 14 09:47:54 EDT 2008
Hello
I am working on coocurence matrices in the aim to extract texture
properties from an image (entropy, energy, contrast and correlation). I
use the following classes :
"ScalarImageToGreyLevelCooccurrenceMatrixGenerator" and
"GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator" to obtain a
histogram (cf code). My program works but it gives me the same strange
results with different images. I would know if my program seems correct.
Results:
Contrast = 3.33997e+150
Correlation = 6.9641e+252
Energy = 1.32722e+180
Entropy = 4.05398e+180
The source code is added at the end of the message.
Thank you
--
Christophe LAY
Stagiaire
Bureau N12, Bât. FERMAT
Tel interne : 83 201
CNES - DCT/SI/AP - BPI 1219
18, avenue Edouard Belin
31401 Toulouse Cedex 09 - France
--------------------------------------------------------------------------
#include "itkExceptionObject.h"
#include "otbImage.h"
#include <iostream>
#include "otbImageFileWriter.h"
#include "itkImageRegionIterator.h"
#include "otbImageFileReader.h"
#include "itkScalarImageToGreyLevelCooccurrenceMatrixGenerator.h"
#include "itkGreyLevelCooccurrenceMatrixTextureCoefficientsCalculator.h"
int main(int argc, char ** argv )
{
const char * inputFilename = argv[1];
typedef unsigned char InputPixelType;
const unsigned int Dimension = 2;
typedef itk::Image<InputPixelType,Dimension> InputImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
typedef
itk::Statistics::ScalarImageToGreyLevelCooccurrenceMatrixGenerator<InputImageType> GLCMGeneratorType;
typedef
itk::Statistics::GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator<GLCMGeneratorType::HistogramType> TexCalcType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFilename);
reader->Update();
InputImageType::Pointer block = InputImageType::New();
block->SetRegions(reader->GetOutput()->GetRequestedRegion());
block->Allocate();
GLCMGeneratorType::Pointer glcm = GLCMGeneratorType::New();
glcm->SetInput(block);
InputImageType::OffsetType offset = {1,0};
glcm->SetOffset(offset);
glcm->SetNumberOfBinsPerAxis(256);
glcm->Compute();
TexCalcType::Pointer texCalc = TexCalcType::New();
texCalc->SetHistogram(glcm->GetOutput());
double contrast = texCalc->GetInertia();
double correlation = texCalc->GetCorrelation();
double energy = texCalc->GetEnergy();
double entropy = texCalc->GetEntropy();
std::cout << " Contrast = " << contrast << std::endl;
std::cout << " Correlation = " << correlation<< std::endl;
std::cout << " Energy = " <<energy << std::endl;
std::cout << " Entropy = " << entropy << std::endl;
return EXIT_SUCCESS;
}
--------------------------------------------------------------------------
More information about the Insight-users
mailing list