DICOM(数字图像和医学通讯)图片对医疗图形至关重要,但它们的专门格式可能会使存储和共享变得更加复杂。 将 Dicom 文件转换为更普遍支持的形式,如 PNG 或 JPEG,同时保留基本信息,这些过程简化.

引入

DICOM 是处理、存储、打印和传输医疗图像信息的标准,但其独特性质可能使其与其他系统进行整合或在不同平台上共享具有挑战性.

原則

在进入转换过程之前,请确保您有以下情况:

  • 安装 .NET SDK: 确保您的开发环境与最新版本的 .Net SDk 设置.

  • 添加 Aspose.Imaging 包: 使用 NuGet 在您的项目中包含 aspose:

dotnet add package Aspose.Imaging
  • Metered License Setup:从 Aspose 获取测量许可证并按照下面的方式设置.

步骤指南转换DICOM图像

步骤1:设置测量许可证

要解锁完整的功能,您需要设置测量许可证:

using Aspose.Imaging;

// Initialize metered license
Metered metered = new Metered();
metered.SetMeteredKey("your-public-key", "your-private-key");
Console.WriteLine("Metered license configured successfully.");

步骤2:下载DICOM图像

接下来,下载您的DICOM图像文件:

// Load the DICOM image
string dicomFilePath = @"path\to\dicomfile.dcm";
Image dicomImage = Image.Load(dicomFilePath);
Console.WriteLine("DICOM image loaded successfully.");

步骤3:设置转换设置

现在,定义您要如何转换 DICOM 文件,您可以在 PNG 和 JPEG 格式之间选择.

转换为 PNG

对于无损的压缩和细节保留:

// Save as PNG
string pngFilePath = @"path\to\output.png";
dicomImage.Save(pngFilePath);
Console.WriteLine("DICOM image converted to PNG successfully.");

转换为JPEG

要平衡文件大小和质量,使用 JPEG 格式:

// Save as JPEG with high quality settings
string jpegFilePath = @"path\to\output.jpg";
dicomImage.Save(jpegFilePath, new JpegOptions { Quality = 90 });
Console.WriteLine("DICOM image converted to JPEG successfully.");

完整代码示例

下面是完整的工作代码,表明将DICOM图像转换为PNG或JPEG:

using Aspose.Imaging;

class Program
{
    static void Main(string[] args)
    {
        // Initialize metered license
        Metered metered = new Metered();
        metered.SetMeteredKey("your-public-key", "your-private-key");
        Console.WriteLine("Metered license configured successfully.");

        // Load the DICOM image
        string dicomFilePath = @"path\to\dicomfile.dcm";
        Image dicomImage = Image.Load(dicomFilePath);
        Console.WriteLine("DICOM image loaded successfully.");

        // Save as PNG
        string pngFilePath = @"path\to\output.png";
        dicomImage.Save(pngFilePath);
        Console.WriteLine("DICOM image converted to PNG successfully.");

        // Save as JPEG with high quality settings
        string jpegFilePath = @"path\to\output.jpg";
        dicomImage.Save(jpegFilePath, new JpegOptions { Quality = 90 });
        Console.WriteLine("DICOM image converted to JPEG successfully.");
    }
}

结论

将 DICOM 图像转换为 PNG 或 JPEG 使用 Aspose.Imaging for .NET 简化了存档、共享和分析工作流.

More in this category