python 通过衍射图并生成总和图像,平均图像,stdev图像和真实空间残留图像。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 通过衍射图并生成总和图像,平均图像,stdev图像和真实空间残留图像。相关的知识,希望对你有一定的参考价值。
# Created 2015, Zack Gainsforth
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
from matplotlib.image import imsave
import numpy as np
import sys
import math
import os
from numba import jit
from tifffile import imread
def ComputeFileScalar(FileName):
Arr = imread(FileName)
return np.std(Arr)
### EDIT ME FOR EACH DIFFRACTION MAP!!!! ###
x_pixels = 114
y_pixels = 19
FileFormatStr = '/DanteACI2_05 10 keV/DanteACI2_05 10 keV/DanteACI2_05_%05d.tif'
### DONE EDITING! ###
print 'First pass: compute the average and sum images.'
# Get the first image, and therefore the size of the image.
FileName = os.getcwd() + FileFormatStr % (1)
Arr = imread(FileName).astype('float')
# Get a sum image.
SumImg = np.zeros(Arr.shape).astype('float')
SkippedFiles = 0
for i in range(y_pixels*x_pixels):
FileName = os.getcwd() + FileFormatStr % (i+1)
if not os.path.isfile(FileName):
print "File %s doesn't exist." % FileName
SkippedFiles += 1
continue
print 'Pass 1: ' + FileName
Arr = imread(FileName).astype('float')
SumImg += Arr
np.savetxt('SumImage.txt', SumImg)
AvgImg = np.copy(SumImg) / (y_pixels*x_pixels-SkippedFiles)
np.savetxt('AvgImage.txt', AvgImg)
print 'Second pass: compute the stdev and residual images.'
StDevImage = np.zeros(AvgImg.shape).astype('float')
R = np.zeros((x_pixels,y_pixels), dtype=(float))
S = np.zeros((x_pixels,y_pixels), dtype=(float))
for y in range(y_pixels):
for x in range(x_pixels):
FileName = FileFormatStr % (x + y*x_pixels + 1)
FileName = os.getcwd() + FileName
if not os.path.isfile(FileName):
R[x,y] = 0
S[x,y] = 0
print "File %s doesn't exist. R=0" % FileName
continue
print 'Pass 2: ' + FileName
Arr = imread(FileName)
StDevArr = (Arr - AvgImg)
R[x,y] = np.sum(np.sum(StDevArr))
S[x,y] = np.std(Arr)
StDevImage += StDevArr**2
# Save the residual image.
np.savetxt('ResidualImage.txt', R)
np.savetxt('SpikeImage.txt', S)
# Save the stdev image
np.savetxt('StDevImage.txt', StDevImage/(x_pixels*y_pixels-SkippedFiles))
print 'Done'
以上是关于python 通过衍射图并生成总和图像,平均图像,stdev图像和真实空间残留图像。的主要内容,如果未能解决你的问题,请参考以下文章