2017-10-21 624 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 
    } 
}