我写了这个脚本来打开原始图像并进行一些处理。
import numpy as np
import matplotlib.pyplot as plt
PATH = "C:\Users\Documents\script_testing_folder\\"
IMAGE_PATH = PATH +"simulation01\\15x15_output_det_00001_raw_df_00000.bin"
raw_image = np.fromfile(IMAGE_PATH, dtype=np.uint64)
raw_image.shape = (15,15)
plt.imshow(raw_image,cmap = 'gray')
total_intensity = ndimage.sum(raw_image)
print total_intensity
plt.show()
相反...当我在ImageJ上打开相同的图像(文件>导入>原始(64位真实,15x15长度和宽度))时,我有这个:
我试过环顾四周,但我不确定在尝试在python上重现相同图像时我出错了。任何帮助将不胜感激。
此外,当我使用以下方法对图像中的强度求和时:
total_intensity = ndimage.sum(raw_image)
print total_intensity
ÿ 我得到4200794456581938015,而在ImageJ上我得到0.585。
我不确定在这些步骤中我出错了...
谢谢!
编辑:原始文件,如果有人想要重现我得到的结果https://www.dropbox.com/s/po82z4uf2ku7k0e/15x15_output_det_00001_raw_df_00000.bin?dl=0
答案 0 :(得分:4)
问题是数据的endianness(64位浮点数的单字节顺序)。幸运的是,numpy有functionality来解决这个问题:
import numpy as np
import matplotlib.pyplot as plt
# load the image
raw_image = np.fromfile('15x15_output_det_00001_raw_df_00000.bin')
raw_image = np.reshape(raw_image, (15, 15))
# swap the byte order
raw_image = raw_image.byteswap()
# output the sum of the intensities to check
total_intensity = np.sum(raw_image)
print "total intensity:", total_intensity
# plot the image
plt.imshow(raw_image,cmap = 'gray', interpolation='nearest')
plt.show()
输出:
总强度:0.585123878711