在一个窗口中显示许多MRI切片

时间:2018-01-23 23:39:24

标签: c++ qt vtk qvtkwidget

是否可以在一个VTK或甚至QT窗口中并排显示所有MRI图像? 到目前为止,我已经从矩阵向量中重建了所有MRI切片,我可以滚动它们(用c ++编写)。我不知道是否可以将所有这些图像放在一个窗口中并显示它们。下面我用我想要实现的内容附上示例图像。感谢您的回复。

MRI Slices

1 个答案:

答案 0 :(得分:1)

为了实现您的目标,您可以将其划分为一系列连续步骤:

  • 首先,您需要扫描并阅读MRI dicom文件,这可以通过vtkDICOMDirectoryvtkDICOMReader完成。
  • 假设您有一个MRI卷,您可以通过vtkExtractVOI提取每个切片,并将此信息映射到vtkImageActor,您可以将其添加到渲染器。反过来,您需要在渲染器上设置视口,以便您可以根据需要并排显示图像。

这是一个小例子,请根据您的需要进行调整:

//Use vtkDICOMDirectory to scan a directory with MRI images
vtkSmartPointer<vtkDICOMDirectory> dicomDir = vtkSmartPointer<vtkDICOMDirectory>::New();
dicomDir->SetDirectoryName("**Insert the path to your images here**");
dicomDir->RequirePixelDataOn();
dicomDir->Update();

int n = dicomDir->GetNumberOfSeries();

vtkSmartPointer<vtkDICOMReader> reader = vtkSmartPointer<vtkDICOMReader>::New();

if (n > 0){
    //Read the first series found (just for example)
    reader->SetFileNames(dicomDir->GetFileNamesForSeries(0));
    reader->Update();

    //Get the extent
    vtkImageData* mriVolume = reader->GetOutput();
    mriVolume->GetExtent(mriExtent);
    xmin = mriExtent[0];
    xmax = mriExtent[1];
    ymin = mriExtent[2];
    ymax = mriExtent[3];
    zmin = mriExtent[4];
    zmax = mriExtent[5];

    //Extract a slice of interest
    vtkSmartPointer<vtkExtractVOI> extractSlice = vtkSmartPointer<vtkExtractVOI>::New();
    extractSlice->SetInputData(mriVolume);

    // Define viewport ranges (Adapt here to it covers your entire range of slices. Here we only create 4 viewports, so 4 images in total)
    double xmins[4] = {0,.5,0,.5};
    double xmaxs[4] = {0.5,1,0.5,1};
    double ymins[4] = {0,0,.5,.5};
    double ymaxs[4]= {0.5,0.5,1,1};

    vtkImageData* slice;

    for(unsigned i = 0; i < 4; i++){
        extractSlice->SetVOI(xmin,xmax,ymin,ymax,i,i);
        extractSlice->Update();

        //Get the image data
        slice = extractSlice->GetOutput();

        //Image Actor
        vtkSmartPointer<vtkImageActor> imageActor = vtkSmartPointer<vtkImageActor>::New();
        imageActor->GetMapper()->SetInputData(slice);

        //Add a renderer
        vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
        renderer->SetViewport(xmins[i],ymins[i],xmaxs[i],ymaxs[i]);
        renderer->AddActor(imageActor);
        renderer->ResetCamera();

        //QT+VTK connection (assumes you have a QVTKWidget named mriWidget)
        ui->mriWidget->GetRenderWindow()->AddRenderer(renderer);
        ui->mriWidget->GetRenderWindow()->Render();
    }
} else {
    std::cerr << "No DICOM images in directory!" << std::endl;
}

<强>参考