[Insight-users] Problem computing coocurence matrix

M.Staring at lumc.nl M.Staring at lumc.nl
Wed May 14 10:10:16 EDT 2008


Hi Christophe,

maybe you need to set:

glcm->SetNormalizeOn();

I recently reprogrammed the GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator. It now only uses one loop over the histogram instead of 3 or 4. You can find the code attached.

Cheers,

Marius
 

> -----Original Message-----
> From: insight-users-bounces at itk.org 
> [mailto:insight-users-bounces at itk.org] On Behalf Of Christophe Lay
> Sent: Wednesday, May 14, 2008 3:48 PM
> To: insight-users at itk.org
> Subject: [Insight-users] Problem computing coocurence matrix
> 
> 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::ScalarImageToGreyLevelCooccurrenceMatrixGener
> ator<InputImageType> GLCMGeneratorType;
> 	typedef
> itk::Statistics::GreyLevelCooccurrenceMatrixTextureCoefficient
> sCalculator<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;
> }
> 
> --------------------------------------------------------------
> ------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 8.0.100 / Virus Database: 269.23.16/1432 - Release 
> Date: 5/14/2008 7:49 AM
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: texture.zip
Type: application/x-zip-compressed
Size: 16550 bytes
Desc: texture.zip
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080514/35bcef4f/attachment-0001.bin>


More information about the Insight-users mailing list