在PHP中,可以使用dicomphp
库来解析DICOM(Digital Imaging and Communications in Medicine)文件。以下是一个简单的示例,展示了如何使用dicomphp
库读取和解析DICOM文件:
- 首先,确保已经安装了
dicomphp
库。如果尚未安装,可以使用Composer进行安装:
composer require redcap/dicom-php
- 创建一个PHP脚本,例如
parse_dicom.php
,并在其中编写以下代码:
read($dicomFilePath); // 获取DICOM文件的元数据 $metadata = https://www.yisu.com/ask/$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 = https://www.yisu.com/ask/$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/