从给定的2维数据生成多个2维数据

时间:2016-09-02 13:20:34

标签: python

我的CCD有512 x512单帧数据(参考)。我需要生成100000,512x512帧,每帧中像素值的总和应该给出参考帧中相应像素的实际值。你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

我想你想用随机值生成1000000帧?这是一种方法。出于简单性和内存原因,我将仅采用3x3数据而不是512x512,并且仅生成10帧而不是100000

#I will generate a random reference with size 3x3, 
#you can take your original CCD data
reference = np.random.random(size=(3,3))
>>> reference
array([[ 0.68618373,  0.69455787,  0.14494262],
       [ 0.83277638,  0.63792746,  0.27089728],
       [ 0.21380624,  0.30595052,  0.26136707]])

#Generate 10 random frames of size 3x3
frames = np.random.random(size=(10,3,3))

#Now normalize those random values such that their sum will result
#in your reference
frames = frames/np.sum(frames, axis=0)*reference

#Check whether the sum of all frames equals the reference
>>> np.sum(frames, axis=0)
array([[ 0.68618373,  0.69455787,  0.14494262],
       [ 0.83277638,  0.63792746,  0.27089728],
       [ 0.21380624,  0.30595052,  0.26136707]])

但是,请考虑帧数之和不等于您的参考完全

>>> np.sum(frames, axis=0)-reference
array([[  0.00000000e+00,  -1.11022302e-16,   0.00000000e+00],
       [  0.00000000e+00,  -1.11022302e-16,   0.00000000e+00],
       [ -2.77555756e-17,   0.00000000e+00,   5.55111512e-17]])

这是出于精确原因,可能会出现问题,具体取决于您的实际任务......