java 生成 dicom uid_如何为DICOM文件生成SOPInstance UID?

这篇博客介绍了在DICOM标准中如何通过UUID创建StudyUID、SeriesUID和SOPInstanceUID。文章提供了两种C#代码示例,展示了如何将UUID转换为DICOM UID,包括一个基于字符串解析的方法和一个更快的直接转换方法。这两种方法都涉及到将UUID的字节顺序调整以符合DICOM标准的要求。
摘要由CSDN通过智能技术生成

DICOM中有两种创建uid的方法。一个基于注册的UID根,另一个基于UUID。后一种方法于2012年与CP-1156一起添加到DICOM标准中。可以通过将UUID转换为DICOM UID来创建诸如Study UID、Series UID、SOP Instance UID之类的UID。

大多数编程语言都内置了创建UUID的支持。下面的示例代码基于GUID值在C中创建一个有效的DICOM UID。public static string GuidToUidStringUsingStringAndParse(Guid value)

{

var guidBytes = string.Format("0{0:N}", value);

var bigInteger = BigInteger.Parse(guidBytes, NumberStyles.HexNumber);

return string.Format(CultureInfo.InvariantCulture, "2.25.{0}", bigInteger);

}

以下方法的速度与此相同,但大约快5倍:public static string ConvertGuidToUuidInteger(ref Guid value)

{

// ISO/IEC 9834-8, paragraph 6.3 (referenced by DICOM PS 3.5, B.2) defines how

// to convert a UUID to a single integer value that can be converted back into a UUID.

// The Guid.ToByteArray Method returns the array in a strange order (see .NET docs),

// BigInteger expects the input array in little endian order.

// The last byte controls the sign, add an additional zero to ensure

// the array is parsed as a positive number.

var octets = value.ToByteArray();

var littleEndianOrder = new byte[]

{ octets[15], octets[14], octets[13], octets[12], octets[11], octets[10], octets[9], octets[8],

octets[6], octets[7], octets[4], octets[5], octets[0], octets[1], octets[2], octets[3], 0 };

return "2.25." + new BigInteger(littleEndianOrder).ToString(CultureInfo.InvariantCulture);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值