运行时警告:在ushort_scalars中遇到无效值



我正试图从dicom文件中制作T2映射,但我的代码遇到了以下错误:

RuntimeWarning: invalid value encountered in ushort_scalars
T2 map:   if math.log((I8[j][k]) / (I1[j][k])) == 0:
ExampleName.py:91: RuntimeWarning: invalid value encountered in ushort_scalars
if (3.03 - (17.85 + 14.87)) / (math.log((I8[j][k]) / (I1[j][k]))) < 0:
ExampleName.py:93: RuntimeWarning: invalid value encountered in ushort_scalars
elif (3.03-(17.85+14.87))/(math.log((I8[j][k]) / (I1[j][k]))) > 100:
ExampleName.py:96: RuntimeWarning: invalid value encountered in ushort_scalars
T2_map[j,k,i] = ((3.03-(17.85+14.87))/(math.log((I8[j][k]) / (I1[j][k]))))
[[[ 0. nan nan ...  0.  0.  0.]

以下是我正在使用的代码示例:

#start of code snippet
T2_map = np.empty((number_of_segments, number_of_segments, number_of_segments))
for i in range(1, number_of_slices + 1):
if 3 + (i - 1) <= number_of_segments:
I1 = (dcm_pixel_array["array" + str(3 + (i - 1))]) * 2
else:
I1 = (dcm_pixel_array["array" + str(number_of_segments)]) * 2
if 3 + ((7 * number_of_slices) + (i - 1)) <= number_of_segments:
I8 = (dcm_pixel_array["array" + str(3 + ((7*number_of_slices) + (i-1)))]) * 2
else:
I8 = (dcm_pixel_array["array" + str(number_of_segments)]) * 2
for j in range(I1.ndim):
for k in range(I1[0].ndim):
if math.log((I8[j][k]) / (I1[j][k])) == 0:
T2_map[j,k,i] = "NAN"
else:
if (3.03 - (17.85 + 14.87)) / (math.log((I8[j][k]) / (I1[j][k]))) < 0:
T2_map[j,k,i] = 0
elif (3.03-(17.85+14.87))/(math.log((I8[j][k]) / (I1[j][k]))) > 100:
T2_map[j,k,i] = 100
else:
T2_map[j,k,i] = ((3.03-(17.85+14.87))/(math.log((I8[j][k]) / (I1[j][k]))))
#end of code snippet

澄清:段数=288

我不知道这些错误是什么意思,也不知道该怎么纠正。欢迎任何建议。

谢谢你的帮助!

问题是我的程序在某个点被零除,所以我必须放入一个if语句,检查I1和I8/I1是否为零值。如果任意一个为0,则我设置T2[j,k,I]="0";NAN";。

最新更新