使用 Python 进行 DICOM 图像调整大小
创建 Python 应用程序以通过服务器 API 调整 DICOM 图像和照片的大小
如何使用 Python 调整 DICOM 图像和照片的大小
在准备用于网站发布的图像和照片时,考虑网络技术的特殊性至关重要。此过程的一个关键方面涉及调整图像的大小。通常需要缩小图像并以各种分辨率保存文件。例如,具有预览功能的图库页面应包含小文件缩略图,而指定用于查看所选图像的页面必须提供高分辨率选项。调整大文件的大小可以通过减少像素总数来实现,但文件大小的减少必须在不影响图像质量的情况下进行。在缩放过程中,重要的是要考虑数据压缩设置以保持图像大小和质量之间的平衡。较小的图像加载速度更快,这对于移动连接来说是一个特别显着的优势,最终增强网站上的用户体验。使用 Python 库可以轻松实现批量文件大小自动转换。要调整 DICOM 图像的大小,我们将使用 Aspose.Imaging for Python via .NET API 是一个功能丰富、功能强大且易于使用的图像处理和转换 API,适用于 Python 平台。您可以使用系统命令中的以下命令安装它。
系统命令行
>> pip install aspose-imaging-python-net
通过 Python 调整 DICOM 大小的步骤
您需要 aspose-imaging-python-net 在您自己的环境中尝试以下工作流程。
- 使用 Image.Load 方法加载 DICOM 文件 +调整图像大小
- 以 Aspose.Imaging 支持的格式将调整大小的图像保存到光盘
系统要求
所有主要操作系统都支持 Python 的 Aspose.Imaging。只需确保您具有以下先决条件。
- 带有 .NET Core 运行时的 Microsoft Windows / Linux。
- Python 和 PyPi 包管理器。
调整 DICOM 图像大小 - Python
from aspose.imaging import Image, ResizeType | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
obj_init = [] | |
obj_init.append("png") | |
obj_init.append("bmp") | |
obj_init.append("apng") | |
obj_init.append("dicom") | |
obj_init.append("jpg") | |
obj_init.append("jp2") | |
obj_init.append("j2k") | |
obj_init.append("tga") | |
obj_init.append("webp") | |
obj_init.append("tiff") | |
obj_init.append("gif") | |
raster_formats = obj_init | |
i = 0 | |
resize_types = list(ResizeType) | |
for format_ext in raster_formats: | |
input_file = os.path.join(templates_folder, f"template.{format_ext}") | |
output_file = os.path.join(templates_folder, f"resized.{format_ext}") | |
new_width = 100 | |
new_height = 100 | |
with Image.load(input_file) as image: | |
# Resize operation supports 16 possible types: | |
# LeftTopToLeftTop, RightTopToRightTop, RightBottomToRightBottom, | |
# LeftBottomToLeftBottom, CenterToCenter, LanczosResample, | |
# NearestNeighbourResample, AdaptiveResample, BilinearResample, | |
# HighQualityResample, CatmullRom, CubicConvolution, | |
# CubicBSpline, Mitchell, SinC | |
# More information available at https://apireference.aspose.com/imaging/python-net/aspose.imaging/resizetype | |
# and https://apireference.aspose.com/imaging/python-net/aspose.imaging.image/resize | |
image.resize(new_width, new_height, resize_types[i]) | |
i += 1 | |
image.save(output_file) | |
if delete_output: | |
os.remove(output_file) |
关于 Python API 的 Aspose.Imaging
Aspose.Imaging API 是一种图像处理解决方案,用于在应用程序中创建、修改、绘制或转换图像(照片)。它提供:跨平台的图像处理,包括但不限于各种图像格式之间的转换(包括统一的多页或多帧图像处理)、绘图等修改、使用图形基元、转换(调整大小、裁剪、翻转和旋转) 、二值化、灰度、调整)、高级图像处理功能(过滤、抖动、遮罩、去偏斜)和内存优化策略。它是一个独立的库,不依赖任何软件进行图像操作。可以在项目中使用原生 API 轻松添加高性能图像转换功能。这些是 100% 私有的本地 API,图像在您的服务器上处理。通过在线应用调整 DICOM 的大小
通过访问我们的 Live Demos 网站 调整 DICOM 文档的大小。 现场演示有以下好处
DICOM 什么是 DICOM 文件格式
DICOM 是 Digital Imaging and Communications in Medicine 的首字母缩写词,属于医学信息学领域。 DICOM 是文件格式定义和网络通信协议的结合。 DICOM 使用 .DCM 扩展名。 .DCM 以两种不同的格式存在,即格式 1.x 和格式 2.x。 DCM Format 1.x 还提供了两个普通版本和扩展版本。 DICOM 用于集成来自不同供应商的打印机、服务器、扫描仪等医疗成像设备,还包含每个患者的唯一识别数据。如果 DICOM 文件能够接收 DICOM 格式的图像数据,则它们可以在两方之间共享。 DICOM的通信部分是应用层协议,实体之间使用TCP/IP进行通信。 HTTP 和 HTTPS 协议用于 DICOM 的 Web 服务。 Web 服务支持的版本是 1.0、1.1、2 或更高版本。
阅读更多