FloatType图像ITK上的分割故障



我在试图显示或将任何过滤器应用于 ikt ::带有float Pixel types 的图像时获得分割故障。我可以使用相同的代码(交换像素类型)以使用>未签名的char Pixel类型打开图像,并且它可以很好地工作。我提到的两个图像(浮动像素和未签名的char One)都是Nifti类型的。

我还使用ImageIobase打开了图像以检查像素类型及其确实浮动。

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkExtractImageFilter.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkImageViewer.h"
#include "vtkImageMapper3D.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkImageActor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"
#include "itkRGBPixel.h"
#include <unistd.h>
#include "QuickView.h"
#include <armadillo>
#include "itkBinaryThresholdImageFilter.h"
#include "itkMedianImageFilter.h"

typedef float FloatPixelType;
typedef itk::Image<FloatPixelType,  3> Input3DFloatImageType;
typedef itk::Image<FloatPixelType, 2> FloatImageType;
typedef itk::ImageFileReader< Input3DFloatImageType> Float3DReaderType;
typedef itk::ImageToVTKImageFilter<FloatImageType> FloatConnectorType;
typedef itk::ExtractImageFilter< Input3DFloatImageType, FloatImageType > FloatFilterType;
int main(int argc, char *argv[]){
const char * grayMatterFile = "../../I3T/I3TGM.img";
Float3DReaderType::Pointer floatReader = Float3DReaderType::New();
floatReader->SetFileName( grayMatterFile );
FloatFilterType::Pointer floatFilter = FloatFilterType::New();
floatFilter->SetDirectionCollapseToSubmatrix();
floatFilter->InPlaceOn();
floatReader->UpdateOutputInformation();
Input3DFloatImageType::RegionType floatRegion = floatReader->GetOutput()->GetLargestPossibleRegion();
Input3DFloatImageType::SizeType floatSize = floatRegion.GetSize();
floatSize[1] = 0;
Input3DFloatImageType::IndexType floatIndexStart = floatRegion.GetIndex();
for(int i = 0; floatRegion.GetSize()[1]; i++){
        
        floatIndexStart[1] = i;
        Input3DFloatImageType::RegionType floatDesiredRegion;
        
        floatDesiredRegion.SetSize( floatSize);
        floatDesiredRegion.SetIndex( floatIndexStart);
    
        // Float image
        floatFilter->SetInput( floatReader->GetOutput() );
        floatFilter->SetExtractionRegion( floatDesiredRegion ); 
        floatFilter->Update();
        ShowImage<FloatImageType>(floatFilter->GetOutput());
    
    
    }
}
template<typename TImageType>
void ShowImage(typename TImageType::Pointer image){
    typedef itk::ImageToVTKImageFilter<TImageType> ThisConnectorType;
    typename ThisConnectorType::Pointer connector = ThisConnectorType::New();
    connector->SetInput(image);
    try{
        connector->Update();
     } catch( itk::ExceptionObject & error ) {
        std::cerr << "Error: " << error << std::endl;
        return;
     }

    vtkSmartPointer<vtkImageActor> actor =  vtkSmartPointer<vtkImageActor>::New();
    actor->GetMapper()->SetInputData(connector->GetOutput());
    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    renderer->ResetCamera();
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    vtkSmartPointer<vtkInteractorStyleImage> style = vtkSmartPointer<vtkInteractorStyleImage>::New();
    renderWindowInteractor->SetInteractorStyle(style);
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderWindowInteractor->Initialize();
    renderWindowInteractor->Start();
}

分段故障在线发生:floatfilter-&gt; update();

您在ShowImage之前缺少floatFilter->Update();

编辑:

您的更新代码(带有次要修改)在我的计算机上运行。您的ITK或VTK的安装可能会破坏。尝试使用IDE在调试模式下运行它,这将向您显示出发生故障的位置。

相关内容

  • 没有找到相关文章