[Insight-users] characteristics
Luis Ibanez
luis.ibanez at kitware.com
Mon, 26 Apr 2004 21:56:37 -0400
Hi David:
Two errors:
1) You are not calling "Compute()" in the ImageMomentCalculator.
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageMomentsCalculator.html#a2
Therefore, when you try to get the Center of Gravity you are
triggering and exception,... that you don't see, because of
error 2 (below)
2) You should have placed a try/catch block around your code
and in the catch block, print out the description of the
potential exception being thrown.
Also note that here you are feeding the ImageMomentCalculator
with the image read directly from a file. Does this file already
have a single region isolated ? Your original problem was to
find the centers and radious of a set of circles in an image.
For the ImageMomentCalcultor to work for this purpose, you must
first isolate the circles, one per image.
Regards,
Luis
----------------------
David Llanos wrote:
> Hi Luis,
>
> I proved to obtain the the coordinates of the center of gravity, and the
> total mass of the object with itkImageMomentsCalculator, but I don't obtain
> the wanted results. with both methods I obtain 1.
> would you be so kind of revising me the code? you the enclosed thing next:
> ---------------------------------------------------------------------
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImageMomentsCalculator.h"
>
> int main( int argc, char *argv[] )
> {
>
> typedef unsigned char PixelType;
> typedef float AccumulatorPixelType;
> const unsigned int Dimension = 2;
> typedef itk::Image< PixelType, Dimension > ImageType;
> typedef itk::ImageFileReader< ImageType > ReaderType;
>
> typedef itk::ImageMomentsCalculator<ImageType> caracteristicas;
>
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName( argv[1] );
> reader->Update();
>
> caracteristicas::Pointer imagen = caracteristicas::New();
> imagen-> SetImage ( reader->GetOutput() );
>
>
> std::cout << "Centro de gravedad: " << imagen-> GetCenterOfGravity <<
> std::endl;
> std::cout << "Masa total: " << imagen-> GetTotalMass << std::endl;
> return 0;
> }
> ---------------------------------------------------------------------
> E:\radioycdg\radio.cxx(25) : warning C4761: integral size mismatch in
> argument; conversion supplied
> E:\radioycdg\radio.cxx(26) : warning C4761: integral size mismatch in
> argument; conversion supplied
> ---------------------------------------------------------------------
>
> if I use the methods in the way GetCenterOfGravity() and GetTotalMass(), I
> don't obtain warnings, but in the execution it leaves me abnormal program
> termination.
>
> Thanks and advange and regards,
>
> David.
>
> ----- Original Message -----
> From: "Luis Ibanez" <luis.ibanez at kitware.com>
> To: "David Llanos" <gva02 at elai.upm.es>
> Cc: <insight-users at itk.org>
> Sent: Friday, April 23, 2004 3:17 AM
> Subject: Re: [Insight-users] characteristics
>
>
>
>>Hi David,
>>
>>Here are two possible options.
>>
>>
>>A) Now that you have labelled the componets
>> you could generate N binary images, each
>> one having one of the objects in the image.
>> If you feed these binary images into the
>> ImageMomentsCalculator
>>
>
> http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageMomentsCalculator.html
>
>> you will be able to easily compute the
>> coordinates of the center of gravity, and
>> the total mass of the object. Given that
>> you know the intensity of the mask, this
>> mass value is proportional to the surface
>> of the object and therefore you can use it
>> for estimating the radius. (Assuming that
>> the object is actually circular).
>>
>>
>>B) If you feel adventurous, You could modify the
>> code of the ImageMomentsCalculator for accepting
>> an additional parameter. This parameter will be
>> a label value. Then you go to the Compute() method
>> in itkImageMomentsCalculator.txx and introduce
>> an IF statement in all the places moments are
>> being computed. The IF should be such that only
>> the pixels with intensity equal to the label are
>> taken into account.
>>
>> You will find the ImageMomentsCalculator under
>> Insight/Code/Algorithms.
>>
>>
>>
>>Note that in both cases you could use the second moments
>>in order to estimate how far are the shapes from being
>>circular. If you eigen-analysis the matrix of second order
>>moments, the ratio of the eigen values will give you an
>>estimation of excentricity, while the eigen-vectors will
>>give you orientation. The ratio between second order
>>moments and zero order moment will allow you to note if
>>the shapes have any holes (e.g. like a ring), or
>>invaginations and protrusions (e.g. like a star).
>>
>>
>>
>> Regards,
>>
>>
>>
>> Luis
>>
>>
>>---------------------
>>David Llanos wrote:
>>
>>
>>>hi all,
>>>
>>>I am looking for classes and methods to obtain characteristic of several
>>>objects on a binary image, being the objects separate white parts on
>>>black bottom. Of each object I want to obtain the radius and the gravity
>>>center.
>>>With Ivan Macia's help I believe that I have gotten the first
>>>requirement for this objective that is to label this objects, by means
>>>of the following code (please, indicate me you if there is some error or
>>>if the one labeled is not correct):
>>
>>--------------------------------------------------------------------------
>
> --------------------------------
>
>>> .....
>>> xorfilter->SetInput1( grindpeak->GetOutput() );
>>> xorfilter->SetInput2( binaryDilate->GetOutput() );
>>> imgEsperBWsin->SetInput( xorfilter->GetOutput() );
>>> imgEsperBWsin->Update();
>>> std::cout << "Numero de iteraciones: " <<
>>>grindpeak->GetNumberOfIterationsUsed() << " .....bordes borrados" <<
>>>std::endl;
>>> std::cout << "Imagen imgEsperBWsin.jpg creada... " << std::endl;
>>>
>>>// Etiquetado de la imagen
>>> itkConnectedComponentFilterType::Pointer labeller =
>>> itkConnectedComponentFilterType::New();
>>> labeller->SetInput( xorfilter->GetOutput() );
>>> labeller->Update();
>>>
>>> itkRelabelComponentFilterType::Pointer relabeller =
>>>itkRelabelComponentFilterType::New();
>>> relabeller->SetInput( labeller->GetOutput() );
>>> relabeller->Update();
>>>
>>> // Muestra de resultados
>>> unsigned long nObjects = relabeller->GetNumberOfObjects();
>>> const std::vector<unsigned long> sizeOfObjects =
>>>relabeller->GetSizeOfObjectsInPixels();
>>> std::cout << "Number of objects : " << nObjects << std::endl;
>>> std::vector<unsigned long>::const_iterator it;
>>> int i;
>>> for(i = 0, it = sizeOfObjects.begin(); it != sizeOfObjects.end(); ++i,
>>>++it) {
>>> std::cout << "Size of object " << i+1 << ": " << (*it) << " pixels" <<
>>>std::endl;
>>> }
>>
>>--------------------------------------------------------------------------
>
> ------------------------------------
>
>>>I now need to obtain the radius and the gravity center (two coordinates)
>>>of each object, but the classes itkRelabelComponentImageFilter and
>>>itkConnectedComponentImageFilter they don't have the methods for it, I
>>>eat for example -> GetRadius ().
>>>Do I have that instantiate "labeller" or "relabeller" with another
>>>class? which advise me you that it uses?
>>>
>>>I attach an example image so that you see to that refer
>>>
>>>Thanks in advange and regards,
>>>
>>>David
>>>
>>>
>>>
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>
>>
>>
>>
>
>