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);
}
A]递增计数器[不推荐]
一个简单的逻辑是获取serieinstanceuid并将其递增1。 因此,假设您的serieInstanceUid是“1.1.1.1.1”,那么您的SOPInstanceUID可能是“1.1.1.1.2”或“1.1.1.1.1”。
问题:
B]日期时间[不推荐]
通常使用的其他技术是将时间戳(带有记号)附加到组织根目录。
问题:
C]更复杂[推荐]
其中:
1.2.840.xxxxx:组织根
30:应用程序ID
152:应用程序版本
99999:安装/位置ID
235:研究ID
20:序列号
100:图像编号
yyyymmddhhmms:日期时间
zzzzzz:线程安全计数器/随机数
问题:
D]UUID派生的UID[推荐]
UID可以从根“2.25”生成,后跟通用唯一标识符(UUID)的十进制表示。
问题:
DICOM中有两种创建uid的方法。一个基于注册的UID根,另一个基于UUID。后一种方法于2012年与CP-1156一起添加到DICOM标准中。可以通过将UUID转换为DICOM UID来创建诸如Study UID、Series UID、SOP Instance UID之类的UID。
大多数编程语言都内置了创建UUID的支持。下面的示例代码基于GUID值在C中创建一个有效的DICOM UID。
以下方法的速度与此相同,但大约快5倍:
我真的建议你不要自己去实现它。如今,大多数语言都提供了UUID库,而不是重新发明轮子。特别是,如果要编写代码来提取MAC地址,用portableC编写可能会非常复杂
UUID不完全符合DICOM定义,因此您需要注册自己的组织根UID,然后简单地填充生成的UUID,该UUID带来空间和时间唯一性条件。
注意,在值表示UI中有64个字节(已经足够了,请参见here)用于存储:
([0-9.]+)
Org Root
\0
(0二进制)填充。最后,因为您使用的是python,所以请使用uuid libpython-uuid。
上述内容应视为标准中正式定义的替代实施:
当直接将UUID转换为UID时,必须使用“2.25.”根。
相关问题 更多 >
编程相关推荐