[Insight-users] itkSpatialObjectToImageStatisticsCalculator problem
Julien Jomier
jjomier at cs . unc . edu
Fri, 8 Aug 2003 12:23:25 -0400
Hi Benjamin,
Your code looks good.
I think the problem comes from the spacing. Can you try to remove the =
line:
> ellipse->SetSpacing(imageReader->GetOutput()->GetSpacing());
and see if the calculator has a correct behavior.
Let me know if this was the problem and I'll fix the code.
Thanks for the report.
Julien
> -----Original Message-----
> From: insight-users-admin at itk . org=20
> [mailto:insight-users-admin at itk . org] On Behalf Of Benjamin King
> Sent: Friday, August 08, 2003 12:08 PM
> To: insight-users at itk . org
> Subject: [Insight-users]=20
> itkSpatialObjectToImageStatisticsCalculator problem
>=20
>=20
> Hello all,
>=20
> I'd like to compute the mean and standard deviation of a part=20
> of an image.=20
> That part is described by a sphere i.e. by the center's=20
> coordinates and a=20
> radius.
> The following program is what I came up with, but it behaves=20
> strangely.=20
> Most of the time, the output is "-1.#IND 0", sometimes it looks like=20
> something sensible, but I can't be sure about that. If I have=20
> a working set=20
> of input parameters, little variations of x, y or z lead to=20
> desaster aka "-=20
> 1.#IND 0". I can vary the radius without that effect.
>=20
> Also, I think that statistics->Update() should Update() the=20
> imageReader and=20
> ellipse, but when I start the program with a filename that=20
> doesn't exist,=20
> there is no complaint.
>=20
> Any help/ideas are much appreciated, here is my code:
>=20
> ---
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkSpatialObject.h"
> #include "itkEllipseSpatialObject.h"
> #include "itkSpatialObjectToImageStatisticsCalculator.h"
> #include "itkAffineTransform.h"
> #include <iostream>
>=20
> using std::cout;
> using std::endl;
>=20
> int main(int argc, char** argv)
> {
> #define DIMENSION 3
> if (argc !=3D 6) {
> cout << "\nVolume Statistics\n\n"
> "This program computes the mean and standard deviation of \n"
> "a ball shaped region in a " << DIMENSION << " dimensional=20
> image.\n\n"
> "USAGE:\n"
> " volumestatistics <input file> <x> <y> <z> <radius>\n"
> " <input file>: " << DIMENSION<< "d 16bit=20
> Analyze/Dicom file\n"
> " <x>: x coordinate of the ball's center\n"
> " <y>: y coordinate of the ball's center\n"
> " <z>: z coordinate of the ball's center\n"
> " <radius>: radius of the ball\n\n"
> "HINT: Define the center coordinate and the radius with=20
> respect to=20
> the\n"
> " spacing and origin of your input image.\n\n"
> "OUTPUT:\n"
> " A single line with two floating point numbers <mean>=20
> and <standard=20
> deviation>\n"
> " separated by a space"
> << endl;
>=20
> return 1;
> }
> typedef itk::Image< unsigned short, DIMENSION > ImageType;
> typedef itk::ImageFileReader< ImageType > ReaderType;
> ReaderType::Pointer imageReader =3D ReaderType::New();
> imageReader->SetFileName(argv[1]);
>=20
> // generate a ball centered around (0, 0, 0)
> typedef itk::EllipseSpatialObject< DIMENSION> EllipseType;
> EllipseType::Pointer ellipse =3D EllipseType::New();
> ellipse->SetSpacing(imageReader->GetOutput()->GetSpacing());
> ellipse->SetRadius(atof(argv[5]));
> EllipseType::VectorType offset;
> offset[0] =3D atof(argv[2]);
> offset[1] =3D atof(argv[3]);
> offset[2] =3D atof(argv[4]);
> ellipse->GetIndexToObjectTransform()->SetOffset(offset);
> ellipse->ComputeObjectToParentTransform();
>=20
> // compute the statistics
> typedef itk::SpatialObjectToImageStatisticsCalculator< ImageType,=20
> EllipseType > StatisticsType;
> StatisticsType::Pointer statistic =3D StatisticsType::New();
> statistic->SetImage(imageReader->GetOutput());
> statistic->SetSpatialObject(ellipse);
>=20
> imageReader->Update();
> ellipse->Update();
> statistic->Update();
>=20
> cout << statistic->GetMean()[0] << " " << sqrt(statistic-=20
> >GetCovarianceMatrix()[0][0]) << endl;
>=20
> return 0;
> }
> ---
>=20
>=20
> Best regards,
> Benjamin
>=20
>=20
> --=20
> Benjamin King
> Institut f=FCr Medizinische Informatik
> Medizinische Hochschule Hannover
> Tel.: +49 511 532-2663=20
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org=20
> http://www . itk . org/mailman/listinfo/insight-> users
>=20