在 Python 中将 DICOM 转换为 PNG

DICOM 文件转换为 PNG 格式在各个行业中至关重要,尤其是在医疗保健领域。DICOM(医学中的数字成像和通信)是医学成像的标准格式。它包含重要数据,包括患者信息。PNG(可移植网络图形)是一种广泛使用的图像格式,以无损压缩而闻名。然而,Python 开发者可以使用 DICOM 到 PNG 转换器来简化 DICOM 到 PNG 的转换过程,从而增强图像处理能力。因此,本文将指导您如何使用 Aspose.Imaging for Python via .NET 在 Python 中将 DICOM 转换为 PNG。

本文涵盖以下部分:

图像处理 SDK 安装

Aspose.Imaging for Python via .NET 简化了在 Python 中将 DICOM 转换为 PNG 的过程。这个图像处理 SDK 提供了强大的图像处理功能,包括格式转换、调整大小和处理。此外,使用 Aspose.Imaging,开发者可以轻松处理各种图像格式,使其成为处理 DICOM 文件的理想选择。

要开始使用 Aspose.Imaging for Python via .NET,请按照以下简单的安装步骤操作:

  1. 访问 下载页面
  2. 使用以下命令安装库:
pip install aspose-imaging-python-net

在 Python 中将 DICOM 转换为 PNG - 代码示例

按照以下步骤使用 Aspose.Imaging for Python via .NET 在 Python 中将 DICOM 转换为 PNG:

  1. 定义文档目录的路径。
  2. 将源文件格式设置为 DicomImage
  3. 通过调用 Image 类的 load 方法加载源 DICOM 文件。
  4. 实例化 PngOptions 类的一个实例。
  5. 调用 save 方法将文件保存为 PNG 图像。

以下是映射这些步骤的 Python 代码片段:

import aspose.pycore as aspycore
from aspose.imaging import Image
from aspose.imaging.fileformats.dicom import DicomImage
from aspose.imaging.imageoptions import PngOptions
import os
# Initialization
def get_data_root_dir_local():
if 'BASE_DIR' in os.environ:
return os.environ["BASE_DIR"]
return "."
# Define the path to the documents directory.
data_dir = '/Desktop/'
input_file = data_dir+"input.dicom"
out_file = data_dir+"output.png"
# Set the fileformat of the source to DicomImage.
# Load the source DICOM file by invoking the load method of the Image class.
with aspycore.as_of(Image.load(input_file), DicomImage) as image:
# Instantiate an instance of the PngOptions class.
options = PngOptions()
# Invoke the save method to save the file as PNG image.
image.save(out_file)
print("DICOM to PNG conversion done.")
输出:
image-manipulation-sdk

获取免费许可证

通过获取免费临时许可证来探索 Aspose 产品。访问 此链接 轻松获取您的许可证并体验 Aspose.Imaging for Python via .NET 的全部功能。

DICOM 到 PNG 转换器 - 在线试用

通过 Aspose DICOM 到 PNG 转换器 轻松测试转换过程。最重要的是,它由 Aspose.Imaging 提供支持。此外,这个免费工具简单易用,在将 DICOM 图像转换为 PNG 格式时提供准确的结果。

dicom-to-png-converter

免费资源

除了本文之外,还有许多资源可以增强您对图像处理的理解。因此,探索文档、教程和论坛,以扩展您在 Aspose.Imaging 和相关技术方面的技能和知识。

结论

使用 Aspose.Imaging for Python via .NET 在 Python 中将 DICOM 转换为 PNG 非常简单。这个强大的图像处理 SDK 简化了流程并增强了图像处理能力。深入了解 Aspose.Imaging,以在您的项目中释放其全部潜力。

如果您有任何问题或需要进一步的帮助,请随时通过我们的 免费支持论坛 与我们联系。

另见