2017-10-21 625 views
0

有没有使用VTK将DICOM(CT扫描)图像转换为点云的方法?DICOM到VTK中的点云

VTK允许读取DICOM和DICOM系列和体绘制,但可以从一系列DICOM图像生成点云吗?

如果在VTK中不可行,是否有其他库可用于此目的?

回答

-1

我想我可能已经找到了一种方法,毕竟。还没有尝试过,但在理论上它应该工作。

首先,DICOM图像需要使用VTK转换为.vtk格式,一旦DICOM图像转换为.vtk,然后可以使用PCL(点云库)将其转换为.pcd(点云格式)。

0

下面是我一直在使用的一些资源,它只适用于非常简单的dicom目录结构:(tbh我不认为VTK有能力执行更复杂的目录...)。但如果它有帮助:

pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>); 

//dicom read 
vtkFileOutputWindow *outwin = vtkFileOutputWindow::New(); 
outwin->SetFileName("vtklog.txt"); 
outwin->SetInstance(outwin); 

vtkSmartPointer<ErrorObserver> errorObserver = vtkSmartPointer<ErrorObserver>::New(); 
vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New(); 

reader->AddObserver(vtkCommand::ErrorEvent, errorObserver); 
reader->AddObserver(vtkCommand::WarningEvent, errorObserver); 

vtkSmartPointer<vtkImageData> sliceData = vtkSmartPointer<vtkImageData>::New(); 
reader->SetDirectoryName(dicomDirectory.c_str()); 
reader->Update(); 

if (errorObserver->GetError() || errorObserver->GetWarning()) 
{ 
    std::cout << "Failed DICOM file access" << std::endl; 
    return false; 
} 

sliceData = reader->GetOutput(); 
outwin->Delete(); 

//extracting pointcloud 
int numberOfDims = sliceData->GetDataDimension(); 

int * dims = sliceData->GetDimensions(); 
std::cout << "Cloud dimensions: "; 
int totalPoints = 1; 
for (int i = 0; i < numberOfDims; i++) 
{ 
    std::cout << dims[i] << " , "; 
    totalPoints = totalPoints * dims[i]; 
} 
std::cout << std::endl; 

std::cout << "Number of dicom points: " << totalPoints << std::endl; 
//generate pcl point cloud 
double* dataRange = sliceData->GetScalarRange(); 
double* spacingData = reader->GetDataSpacing(); 
std::cout << "Data intensity bounds... min: " << dataRange[0] << ", max: " << dataRange[1] << std::endl; 
if (numberOfDims != 3) 
{ 
    std::cout << "Incorrect number of dimensions in dicom file, generation failed..." << std::endl; 
    return false; 
} 
else 
{ 
    double xScale = spacingData[0]; 
    double yScale = spacingData[1]; 
    double zScale = spacingData[2]; 

    std::cout << "x spacing: " << xScale << std::endl; 
    std::cout << "y spacing: " << yScale << std::endl; 
    std::cout << "z spacing: " << zScale << std::endl; 

    for (int z = 0; z < dims[2]; z++) 
    { 
     if (z % 50 == 0) 
     { 
      double percentageComplete = (double)z/(double)dims[2]; 
      std::cout << "Dicom Read Progress: " << (int)(100.0 * percentageComplete) << "%" << std::endl; 
     } 
     for (int y = 0; y < dims[1]; y++) 
     { 
      for (int x = 0; x < dims[0]; x++) 
      { 
       pcl::PointXYZI tempPt = pcl::PointXYZI(); 
       tempPt.x = x * xScale; 
       tempPt.y = y * yScale; 
       tempPt.z = z * zScale; 
       double tempIntensity = sliceData->GetScalarComponentAsDouble(x, y, z, 0); 
       if (!isinf(tempIntensity)) 
       { 
        tempPt.intensity = tempIntensity; 
       } 
       else 
       { 
        tempPt.intensity = 0; 
       } 

       cloud->points.push_back(tempPt); 
      } 
     } 
     std::cout << reader->GetTransferSyntaxUID() << std::endl; 
     //std::cout << reader->get 
    } 
}