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图像和真实空间残留图像。的主要内容,如果未能解决你的问题,请参考以下文章
Python使用matplotlib可视化散点图并在可视化图像的底部和右边添加边缘箱图(Marginal Boxplot)
Python基于MASK信息抽取ROI子图并构建基于迁移学习(densenet)的图像分类器实战(原始影像和mask文件都是二维的情况)
python使用matplotlib可视化时间序列图并在时间序列可视化图像中的不同区域添加动态阈值动态阈值上限动态阈值下限
Python使用matplotlib可视化气泡图并使用encircle函数自定义多边形圈定可视化图像中的指定区域(Bubble plot with Encircling)
Python使用matplotlib可视化散点图并在可视化图像的底部和右边添加边缘直方图自定义边缘直方图的色彩(Marginal Histogram)
R语言ggplot2可视化分面图(faceting)编写自定义函数将生成的分面图分裂成多个子图并按照索引读取对应的可视化图像:Split facet plot into list of plots