【问题标题】:Opening raw images on Python resulting in a different image compared to ImageJ与 ImageJ 相比,在 Python 上打开原始图像会产生不同的图像
【发布时间】:2015-07-29 16:11:55
【问题描述】:

我编写了这个脚本来打开一个原始图像并进行一些处理。

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(file>import>raw (64bit real, 15x15 length and width)) 上打开相同的图像时,我有这个:

我试过环顾四周,但我不确定在 python 上重现相同图像时哪里出错了。任何帮助将不胜感激。

另外,当我使用以下方法对图像中的强度求和时:

total_intensity = ndimage.sum(raw_image)
print total_intensity

y 我得到 4200794456581938015,而在 ImageJ 上我得到 0.585。

我不确定我在这些步骤中哪里出错了......

谢谢!

编辑:如果有人想重现我得到的结果,请使用原始文件https://www.dropbox.com/s/po82z4uf2ku7k0e/15x15_output_det_00001_raw_df_00000.bin?dl=0

【问题讨论】:

  • 你的图片文件是什么格式的?你能把它上传到某个地方吗?
  • 不确定,但我最初的猜测是您想将 dtype 更改为 np.float64,因为 ImageJ 使用所谓的 64 位实数。另外,请注意 ImageJ 中的强度总和是小数。
  • dropbox.com/s/po82z4uf2ku7k0e/… 我试图处理的文件
  • 刚试过float64,没用...
  • raw_image = np.fromfile(IMAGE_PATH, dtype=np.uint64):这是否以正确的方式加载您的数据?如果没有,它可能不会给你一个错误,因为它只是读取二进制数据并以某种方式解释它。我以前从未见过.bin 图像。如果有帮助,有一种方法可以加载 16 位 tif:stackoverflow.com/a/18483020/2156909

标签: python numpy image-processing matplotlib imagej


【解决方案1】:

问题是您的数据的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

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多