当前位置:网站首页>c# - C#用fo-dicom对CT图像的PixelData进行处理和转换
c# - C#用fo-dicom对CT图像的PixelData进行处理和转换
2022-06-30 06:26:00 【sinolover】
转自:c# - C#用fo-dicom对CT图像的PixelData进行处理和转换 - IT工具网
对于某些测试,我试图操纵 PixelData以 dicom 格式存储的 CT 图像的元素,并使用 C# 中的 Fellow Oak Dicom 将其写回文件中。经过一番研究,我发现我想要处理的矩阵在 Buffer 中。的 PixelData存储在 byte -大批。所以我写了以下代码:
DicomFile ctFile = DicomFile.Open(image); var pixDat = ctFile.Dataset.Get<byte[]>(DicomTag.PixelData); for (int i = 0; i < pixData.Length; i++) { pixDat[i] = Convert.ToByte(200); } ctFile.Dataset.AddOrUpdate<byte[]>(DicomTag.PixelData, pixDat); ctFile.Save("new file folder"); 这是我的第一次尝试,我收到了
Exception在 AddOrUpdate命令,因为它无法转换 byte -数组到OB。阅读例如Pianykh 的关于 DICOM 的书,OB 表示其他字节字符串。但到目前为止我无法转换被操纵的
byte -数组到OB。当我尝试这个代码片段时:DicomOtherByte dob = new DicomOtherByte(DicomTag.PixelData, pixDat); ctFile.Dataset.AddOrUpdate<DicomOtherByte>(DicomTag.PixelData, dob); Exception仍然在调用 AddOrUpdate因为无法将项目转换为 OB。在 stackoverflow、git 或 google 中的 fo-dicom 文档中搜索我仍然不知道如何处理它。所以我想知道如何将我的操纵矩阵转换为 OB,因为我认为 DicomOtherByte是OB。编辑:
Exception是“无法使用 Dicom.DicomOtherByte 类型的值创建 OB 类型的 DICOM 元素” - System.InvalidOperationException提前致谢。
最佳答案
Dicom 数据集中的像素数据非常特别。它不能作为单个标签轻松读取或写入。 Fo-Dicom 具有处理像素数据的特殊函数和类。
下面是一个例子:
DicomFile ctFile = DicomFile.Open(@"C:\Temp\original.dcm"); // Create PixelData object to represent pixel data in dataset DicomPixelData pixelData = DicomPixelData.Create(ctFile.Dataset); // Get Raw Data byte[] originalRawBytes = pixelData.GetFrame(0).Data; // Create new array with modified data byte[] modifiedRawBytes = new byte[originalRawBytes.Length]; for (int i = 0; i < originalRawBytes.Length; i++) { modifiedRawBytes[i] = (byte)(originalRawBytes[i] + 100); } // Create new buffer supporting IByteBuffer to contain the modified data MemoryByteBuffer modified = new MemoryByteBuffer(modifiedRawBytes); // Write back modified pixel data ctFile.Dataset.AddOrUpdatePixelData(DicomVR.OB, modified); ctFile.Save(@"C:\Temp\Modified.dcm"); 请注意,有更多的辅助类可以直接以特定格式处理像素数据,例如
PixelDataConverter和 PixelDataFactory .此外,如果您想使用实际图像,请使用
DicomImage类(class)。DicomImage image = new DicomImage(ctFile.Dataset); 关于c# - C#用fo-dicom对CT图像的PixelData进行处理和转换,我们在Stack Overflow上找到一个类似的问题: type conversion - Manipulating and Converting PixelData of CT Image with fo-dicom in C# - Stack Overflow
边栏推荐
- Base64 explanation: playing with pictures Base64 encoding
- Hao looking for a job
- 01. regular expression overview
- 【微信小程序:单选、多选样式,背景色,圆角】
- Switch must be better than if Else fast
- HuaWei满级大牛首次分享出这份598页网络协议全彩手册
- When to use redis
- Zibll子比主题V6.4.1wordpress 开心版源码下载_破解原版/直接使用/无需教程
- Notes of the first week of 2021 Chengdu Arts and Sciences cloud computing intensive training class
- 46. full arrangement -dfs double hundred code
猜你喜欢

Unable to access the Internet at win10 /11 hotspot

Wechat applet mall project

Idea add database

深度学习---三好学生各成绩所占权重问题(3)

One sentence introduction to Trojan horse

1.6 - CPU组成

图像处理7-图像增强

Gazebo installation, uninstall and upgrade

Jgaurora A8 configuration file

Installation and initialization of MariaDB database
随机推荐
ES6 deconstruction assignment
Uniapp wechat applet returns to the previous page and refreshes
Share problems solved
Network basics
Notes of the first week of 2021 Chengdu Arts and Sciences cloud computing intensive training class
Is it safe to open an account online? Can you open an account to speculate on the Internet?
Rhcsa day 3
Develop stylelint rules from zero (plug-ins)
Using C language pure for loop to implement ilovey
SHELL
Practice summary of Prometheus project in amu Laboratory
从底层结构开始学习FPGA----RAM IP核及关键参数介绍
观察者模式、状态模式在实际工作中的使用
ES6扩展运算符(...)
Simple example of class template
C语言:练习题三
Win10 /11 开热点无法上网问题
Who doesn't want a blog site of their own - build a blog site WordPress
Variable parameters of go
Wechat applet mall project