在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/