《itk实用demo》-轮廓提取

轮廓提取

    typedef itk::SimpleContourExtractorImageFilter <ImageType, ImageType>
    SimpleContourExtractorImageFilterType;
    SimpleContourExtractorImageFilterType::Pointer contourFilter
    = SimpleContourExtractorImageFilterType::New();
    contourFilter->SetInput(slicedata);
    contourFilter->Update();
--------------------------------------------------------------------------------
vtkPolyData* getContour(SliceType *slicedata)
{   
    cout<<"start get contour ..."<<endl;

    typedef itk::Image<unsigned char ,2> USliceType ;
    typedef itk::Image<float,2> FSliceType;

    typedef itk::CastImageFilter<SliceType ,USliceType > UCastImageType;
    UCastImageType::Pointer ucastFilter = UCastImageType::New();
    ucastFilter->SetInput(slicedata);
    ucastFilter->Update();
    USliceImageType::Pointer slice2 = ucastFilter->GetOutput();

    //计算每个像素到轮廓的距离
    typedef itk::ApproximateSignedDistanceMapImageFilter<USliceType ,FSliceType> DistanceMapType;
    DistanceMapType::Pointer distanceFilter = DistanceMapType::New();
    distanceFilter->SetInput(ucastFilter->GetOutput());
    distanceFilter->SetInsideValue(255);
    distanceFilter->SetOutsideValue(0);
    try
    {
        distanceFilter->Update();
    }
    catch(itk::ExceptionObject& er)
    {
        cout<<er<<endl;
    }

    //提取轮廓
    typedef itk::ContourExtractor2DImageFilter<FSliceType> ContourExtractorType;
    ContourExtractorType::Pointer contourFilter = ContourExtractorType::New();
    contourFilter->SetInput(distanceFilter->GetOutput());
    contourFilter->SetContourValue(0);
    try
    {
        contourFilter->Update();
    }
    catch(itk::ExceptionObject& er)
    {
        cout<<er<<endl;
    }
    //cout<<"contour num is :"<<contourFilter->GetNumberOfOutputs()<<endl;

    //找出最大轮廓,并依次保存轮廓点
    vtkPolyData* myContour = vtkPolyData::New();

    if (contourFilter->GetNumberOfOutputs()!=0)
    {
        vtkCellArray* cell = vtkCellArray::New();
        vtkPoints* points = vtkPoints::New();
        int pointId = 0 ;   
        int max = contourFilter->GetOutput(0)->GetVertexList()->size();
        int ind = 0;
        for(unsigned int i = 0; i < contourFilter->GetNumberOfOutputs(); ++i)
        {       
            if(contourFilter->GetOutput(i)->GetVertexList()->size()>max)
            {
                max = contourFilter->GetOutput(i)->GetVertexList()->size();
                ind = i;
            }
        }

        //获取轮廓的物理坐标
        //cout<<"contour size is :"<<contourFilter->GetOutput(ind)->GetVertexList()->size()<<endl;
        vtkPolyLine* polyLine = vtkPolyLine::New();
        ContourExtractorType::VertexListType::ConstIterator vertexIterator = contourFilter->GetOutput(ind)->GetVertexList()->Begin();       
        while(vertexIterator != contourFilter->GetOutput(ind)->GetVertexList()->End())
        {
            SliceImageType::PointType pointTemp;
            itk::ContinuousIndex<double,2> continousIndex;
            continousIndex[0] = vertexIterator->Value()[0];
            continousIndex[1] = vertexIterator->Value()[1];
            slicedata->TransformContinuousIndexToPhysicalPoint(continousIndex,pointTemp);
            double point[3];
            point[0] = pointTemp[0]*spacing[0];
            point[1] = pointTemp[1]*spacing[1];
            point[2] =  znum; 
            pointId = points->InsertNextPoint(point);
            polyLine->GetPointIds()->InsertNextId(pointId);
            ++vertexIterator;
        }
        //polyLine->GetPointIds()->InsertNextId(0);
        cell->InsertNextCell(polyLine);
        polyLine->Delete();
        myContour->SetPoints(points);
        myContour->SetLines(cell);
        //myContour->SetPolys(cell);

        cell->Delete();
        myContour->Modified();
        //cout<<"end calc contour ..."<<endl;

        points->Delete();
    }

    return myContour;
}
### 回答1: itksoftwareguide-2.4.0-中文版是一份ITK软件指南的中文版本。ITK(Insight Segmentation and Registration Toolkit)是一个用于图像分割和配准的开源软件库,被广泛用于医学影像处理领域。 这个指南提供了ITK软件的详细说明和使用方法,包括安装、编译、配置和运行等方面的指导。它的内容主要分为几个部分:介绍、基础知识、进阶内容和应用示例。 在介绍部分,读者可以了解到ITK的背景、目标和基本原理,以及它在医学影像处理中的应用领域。基础知识部分深入介绍了ITK的核心概念、数据结构和算法,以及如何使用ITK进行图像处理和分析。 进阶内容部分讲解了更高级的主题,包括多线程编程、可视化、图像配准和分割算法的实现等。应用示例部分提供了一些实际应用场景的案例,帮助读者更好地理解和应用ITK软件。 通过阅读这份指南,读者可以全面了解ITK软件的基本概念和使用方法,掌握图像处理和分割的基本技术,从而能够在医学影像处理领域中进行相关的研究和开发工作。这对于那些对医学影像处理感兴趣的研究者和开发人员来说是非常有价值的参考资料。 ### 回答2: itksoftwareguide-2.4.0中文版是一个关于ITK(Insight Segmentation and Registration Toolkit)软件的指南,该软件是一种用于图像处理和分析的开源工具。该指南介绍了ITK软件的安装、使用和常见问题解答等方面的内容。 首先,ITK软件是一个用C++编写的跨平台的图像处理库,它提供了一系列的图像处理算法和工具。通过使用ITK,用户可以进行图像分割、配准、变形、滤波、重建等各种图像处理和分析任务。 该指南的中文版是为了方便中文用户更好地理解和使用ITK软件而编写的。它详细介绍了ITK软件的安装步骤和配置要求,以及如何加载和使用ITK库。同时,该指南还提供了丰富的实例和示例代码,帮助用户快速上手和学习ITK软件的使用方法。 此外,指南中还涵盖了一些常见问题和解决方法,帮助用户解决在使用ITK软件过程中遇到的困难和错误。用户可以根据具体问题在指南中查找答案,以提高工作效率和准确性。 总而言之,itksoftwareguide-2.4.0-中文版是一本关于ITK软件的详细指南,旨在帮助中文用户更好地理解和使用ITK软件。其内容包括软件安装、使用方法、示例代码和常见问题解答等方面,为使用ITK软件的用户提供了全面的帮助和指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值