ITK-图像处理,计算3D图像的形状特征
ITK-Image processing, calculate shape features for 3D image
我正在尝试使用 ITK 库和 C++ 计算 3D 图像的形状特征。所以我遵循了ITK文档中给出的example。该示例采用 2D 图像,并提取不同的形状特征。在我的程序中,我只想让给定的 3D 图像获取形状属性并将它们存储在 array <double>
.
中
这是我目前的情况:
//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();
我能够读取 3D 图像并计算其形状属性。但是我有这个问题:我无法将它们存储在 array <double>
中,因为 labelObject
方法 returns 是 const
类型。我收到此错误:IntelliSense:没有合适的从 const itk::ImageRegion<3U> 到 "double" 的转换函数存在
有人用 ITK 来做这个吗?如果有任何其他方法可以实现这一点,请问有人能指出解决方案吗?
我们将不胜感激任何帮助
问题不在于 const
类型——您可以从 const
分配 ,只是不允许分配 给他们
问题是 GetBoundingBox()
return 一个 itk::ImageRegion
object, which is a more complicated object that contains Index
and Size
对象作为成员。没有简单的方法可以将其转换为 ITK 理解的 double
,因此尝试将其转换为 double
没有任何意义。
您应该阅读 ShapeLabelObject
class 文档,看看哪些方法 return 类型可以转换为 double
。
例如,GetNumberOfPixels()
方法 return 是 SizeValueType
,它只是 unsigned long
的 typedef
,因此可以将其转换为double
。 GetElongation()
和 GetRoundness()
方法都有 return 类型 const double
所以那些也可以。
我正在尝试使用 ITK 库和 C++ 计算 3D 图像的形状特征。所以我遵循了ITK文档中给出的example。该示例采用 2D 图像,并提取不同的形状特征。在我的程序中,我只想让给定的 3D 图像获取形状属性并将它们存储在 array <double>
.
这是我目前的情况:
//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();
我能够读取 3D 图像并计算其形状属性。但是我有这个问题:我无法将它们存储在 array <double>
中,因为 labelObject
方法 returns 是 const
类型。我收到此错误:IntelliSense:没有合适的从 const itk::ImageRegion<3U> 到 "double" 的转换函数存在
有人用 ITK 来做这个吗?如果有任何其他方法可以实现这一点,请问有人能指出解决方案吗?
我们将不胜感激任何帮助
问题不在于 const
类型——您可以从 const
分配 ,只是不允许分配 给他们
问题是 GetBoundingBox()
return 一个 itk::ImageRegion
object, which is a more complicated object that contains Index
and Size
对象作为成员。没有简单的方法可以将其转换为 ITK 理解的 double
,因此尝试将其转换为 double
没有任何意义。
您应该阅读 ShapeLabelObject
class 文档,看看哪些方法 return 类型可以转换为 double
。
例如,GetNumberOfPixels()
方法 return 是 SizeValueType
,它只是 unsigned long
的 typedef
,因此可以将其转换为double
。 GetElongation()
和 GetRoundness()
方法都有 return 类型 const double
所以那些也可以。