import numpy as np import matplotlib.pylab as plt import scipy.optimize as opt import TEMareels.tools.tifffile as tiff from TEMareels.tools import tvips # define in/outfile name and energy steps pattern = "/path/to/energy_calibration/img%d.tif"; series = [pattern%i for i in range(329,350) if i <> 342] dE = 5; # energy steps in eV outfile = "Ecalibration.tif"; # get image dimensions and energy list image = tvips.load_TVIPS(series[0]); Ny,Nx = image.shape Ns = len(series); E = np.arange(0,Ns*dE,dE); # energies # iterate over all images and extract EELS spectrum x0 = np.zeros(Ns); # center of spectrum dx = np.zeros(Ns); # width of spectrum spectra = np.zeros((Ns,Ny+1)); # extracted EELS spectra for s in range(Ns): image = tvips.load_TVIPS(series[s]); # shape Ny times Nx assert np.allclose(image.shape, (Ny,Nx)); # determine position of spectrum along x-axis by fitting xline = np.sum(image,axis=0);
import numpy as np import matplotlib.pylab as plt import scipy.optimize as opt import TEMareels.tools.tifffile as tiff from TEMareels.tools import tvips # define in/outfile name and energy steps pattern = "/path/to/energy_calibration/img%d.tif" series = [pattern % i for i in range(329, 350) if i <> 342] dE = 5 # energy steps in eV outfile = "Ecalibration.tif" # get image dimensions and energy list image = tvips.load_TVIPS(series[0]) Ny, Nx = image.shape Ns = len(series) E = np.arange(0, Ns * dE, dE) # energies # iterate over all images and extract EELS spectrum x0 = np.zeros(Ns) # center of spectrum dx = np.zeros(Ns) # width of spectrum spectra = np.zeros((Ns, Ny + 1)) # extracted EELS spectra for s in range(Ns): image = tvips.load_TVIPS(series[s])
import _set_pkgdir import glob; import numpy as np import scipy.signal as sig from TEMareels.tools.img_filter import binning from TEMareels.tools import tvips import TEMareels.tools.tifffile as tiff # define infile name and binning along y-direction (E-axis) pattern = "/path/to/q_calibration/img%d.tif"; files = [pattern%i for i in range(344,345)] ybin = 64; for filename in files: image = tvips.load_TVIPS(filename) # img[iy,ix] #image = tiff.imread(filename).astype(np.float64); if ~np.allclose(image.shape, (4096,4096)): raise IOError("Unexpected image size in file '%s'"%filename); medimg= sig.medfilt2d(image,kernel_size=3); # filtering binimg= binning(medimg,ybin); # binning along y #binimg = binning(binimg.T,32).T; # binning along x outfile = filename.split(".tif")[0]+"_filt_bin%d.tif"%ybin; tiff.imsave(outfile,binimg.astype(np.float32));
""" # use TEMareels package specified in _set_pkgdir (overrides PYTHONPATH) import _set_pkgdir import glob import numpy as np import scipy.signal as sig from TEMareels.tools.img_filter import binning from TEMareels.tools import tvips import TEMareels.tools.tifffile as tiff # define infile name and binning along y-direction (E-axis) pattern = "/path/to/q_calibration/img%d.tif" files = [pattern % i for i in range(344, 345)] ybin = 64 for filename in files: image = tvips.load_TVIPS(filename) # img[iy,ix] #image = tiff.imread(filename).astype(np.float64); if ~np.allclose(image.shape, (4096, 4096)): raise IOError("Unexpected image size in file '%s'" % filename) medimg = sig.medfilt2d(image, kernel_size=3) # filtering binimg = binning(medimg, ybin) # binning along y #binimg = binning(binimg.T,32).T; # binning along x outfile = filename.split(".tif")[0] + "_filt_bin%d.tif" % ybin tiff.imsave(outfile, binimg.astype(np.float32))
# reference image for alignment ref_file = files[0]; # first image as anchor box = [0,500,1550,2050]; # reference position for stripe substraction intstart =[150,1025,2700,3800]; intwidth = 200; # outlier options radius = 1; abs_thresh = 30; rel_thresh = 1; ref_img = tvips.load_TVIPS(ref_file) #ref_img = ref_img.repeat(8,axis=0).repeat(8,axis=1); # for testing ref = ref_img[box[0]:box[1],box[2]:box[3]]; stack = []; # OPTIONS outliers = True; # remove outliers stripes = True; # remove stripes alignment = True; # align images final = np.zeros(shape=(4096,4096)) imgcounter = 0; for filename in files: img = tvips.load_TVIPS(filename)
# reference image for alignment ref_file = files[0] # first image as anchor box = [0, 500, 1550, 2050] # reference position for stripe substraction intstart = [150, 1025, 2700, 3800] intwidth = 200 # outlier options radius = 1 abs_thresh = 30 rel_thresh = 1 ref_img = tvips.load_TVIPS(ref_file) #ref_img = ref_img.repeat(8,axis=0).repeat(8,axis=1); # for testing ref = ref_img[box[0]:box[1], box[2]:box[3]] stack = [] # OPTIONS outliers = True # remove outliers stripes = True # remove stripes alignment = True # align images final = np.zeros(shape=(4096, 4096)) imgcounter = 0