在PHP中,可以使用dicomphp
庫來解析DICOM(Digital Imaging and Communications in Medicine)文件。以下是一個簡單的示例,展示了如何使用dicomphp
庫讀取和解析DICOM文件:
dicomphp
庫。如果尚未安裝,可以使用Composer進行安裝:composer require redcap/dicom-php
parse_dicom.php
,并在其中編寫以下代碼:<?php
require_once 'vendor/autoload.php';
use RedCap\Dicom\Dicom;
// 替換為您的DICOM文件路徑
$dicomFilePath = 'path/to/your/dicom/file.dcm';
try {
// 創建一個Dicom對象
$dicom = new Dicom();
// 讀取DICOM文件
$dicom->read($dicomFilePath);
// 獲取DICOM文件的元數據
$metadata = $dicom->getMetadata();
// 輸出DICOM文件的詳細信息
echo "Patient ID: " . $metadata['patient_id'] . "\n";
echo "Study Date: " . $metadata['study_date'] . "\n";
echo "Study Time: " . $metadata['study_time'] . "\n";
echo "Accession Number: " . $metadata['accession_number'] . "\n";
echo "Modality: " . $metadata['modality'] . "\n";
echo "Manufacturer: " . $metadata['manufacturer'] . "\n";
echo "Model: " . $metadata['model'] . "\n";
echo "Software Version: " . $metadata['software_version'] . "\n";
// 獲取DICOM圖像數據
$imageData = $dicom->getImageData();
// 輸出DICOM圖像的寬度和高度
echo "Image Width: " . $imageData['width'] . "\n";
echo "Image Height: " . $imageData['height'] . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
?>
parse_dicom.php
腳本:php parse_dicom.php
這將輸出DICOM文件的元數據和圖像尺寸等信息。您可以根據需要修改代碼以獲取和處理其他DICOM數據。更多關于dicomphp
庫的信息和用法,請參閱官方文檔:https://redcap.github.io/dicom-php/