I'm trying to calculate shape features for a 3D image using ITK library with C++. So I followed the example given in the ITK documentation. The example takes a 2D image, and extracts different shape features. In my program, I just want for a given 3D image to get shapes attributes and stock them in an array <double>
.
Here is what I have so far :
//principal declarations
const unsigned int Dimension = 3;
typedef unsigned char PixelType;
typedef unsigned short LabelType;
typedef itk::Image<PixelType, Dimension> InputImageType;
typedef itk::Image< LabelType, Dimension > OutputImageType;
typedef itk::ShapeLabelObject< LabelType, Dimension > ShapeLabelObjectType;
typedef itk::LabelMap< ShapeLabelObjectType > LabelMapType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
typedef itk::ConnectedComponentImageFilter <InputImageType, OutputImageType > ConnectedComponentImageFilterType;
typedef itk::LabelImageToShapeLabelMapFilter< OutputImageType, LabelMapType> I2LType;
typedef itk::Array< double > MeasurementVectorType;
MeasurementVectorType formes(9);
InputImageType::Pointer image;
//read the 3Dimage
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(file);
reader->Update();
image = reader->GetOutput();
ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New ();
connected->SetInput(image);
connected->Update();
// create the shape label map filter
I2LType::Pointer i2l = I2LType::New();
i2l->SetInput( connected->GetOutput() );
i2l->SetComputePerimeter(true);
i2l->Update();
LabelMapType *labelMap = i2l->GetOutput();
//calculate shape attributes for the first label
ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(0);
//stock the attributes in the array
formes[0]=labelObject->GetBoundingBox();
formes[1]=labelObject->GetNumberOfPixels();
formes[2]=labelObject->GetPhysicalSize();
formes[3]=labelObject->GetElongation();
formes[4]=labelObject->GetPerimeter();
formes[5]=labelObject->GetRoundness();
formes[6]=labelObject->GetEquivalentSphericalRadius();
formes[7]=labelObject->GetEquivalentSphericalPerimeter();
formes[8]=labelObject->GetFlatness();
I was able to read the 3D images and calculate its shape attributes. However I have this problem : i can't stock them in the array <double>
because labelObject
methodes returns a const
type. I get this error : IntelliSense: no suitable conversion function from const itk::ImageRegion<3U> to "double" exists
Does any one used ITK to do this ? If there is any other method to achieve that, could anyone point me to a solution please ?
Any help will be much apreciated
The problem isn't the const
type--you are allowed to assign from const
s, you are just not allowed to assign to them.
The problem is that GetBoundingBox()
returns an itk::ImageRegion
object, which is a more complicated object that contains Index
and Size
objects as members. There is no simple way to cast this to a double
that ITK understands, so trying to cast it to a double
doesn't make sense.
You should go through the ShapeLabelObject
class documentation and see which methods return types that can be cast to double
.
For example, the GetNumberOfPixels()
method returns a SizeValueType
, which is just a typedef
of unsigned long
, so this could be cast to a double
. The GetElongation()
and GetRoundness()
methods both have return type const double
so those will be fine too.