是否可以在一个 VTK 甚至 QT 窗口中并排显示所有 MRI 图像?到目前为止,我已经从矩阵向量中得到了所有重建的 MRI 切片,我可以滚动它们(用 C++ 编写)。我不知道我是否可以将所有这些图像放在一个窗口中并显示它们。下面我附上我想要实现的示例图像。感谢您的任何回复。
问问题
521 次
1 回答
1
为了实现您想要的,您可以将其划分为一系列顺序步骤:
- 首先,您需要扫描和读取 MRI dicom 文件,可以通过
vtkDICOMDirectory
和vtkDICOMReader
. - 假设您有一个 MRI 体积,您可以通过 提取每个切片
vtkExtractVOI
,并将此信息映射到 avtkImageActor
,您可以将其添加到渲染器中。反过来,您需要在渲染器上设置视口,以便您可以根据需要并排显示图像。
这是一个小例子,请根据您的需要进行调整:
//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;
}
参考资料:
于 2018-01-24T23:05:37.720 回答