.edf to .tiff
Copy the py script below in any text editor and save it in a file with a .py extension. In an .edf directory create a folder named "tiff".
You need:
numpy
fabio
glob
os
PIL
astropy.convolution
import numpy as np
import fabio
import glob
import os
from PIL import Image
from astropy.convolution import Gaussian2DKernel, interpolate_replace_nans
# image path and format
path = r'E:\_DATA_\tdown1'
files = glob.glob(path + "/*.edf")
for filename in files:
specname = os.path.split(filename) # get filename
specname = 'fix_%s' % specname[-1] # set a new name to save
pre, ext = os.path.splitext(specname) # get file type
ext = '.tiff' # change to .tiff (for dioptase) comment if .edf is needed
print(pre)
imdat = fabio.open(filename) # open image
# rescale & make it float
img = imdat.data[-1000:1000, 0:4439] * 1e0
# make < 0 values to NaN values
img[img < 0] = np.nan
# smooth with a Gaussian kernel with x_stddev and y_stddev)
kernel = Gaussian2DKernel(x_stddev=3, y_stddev=0.1)
# create a "fixed" image with NaNs replaced by interpolated values
fixed_image = interpolate_replace_nans(img, kernel)
img = Image.fromarray(fixed_image)
# save in a folder named "/tiff/" that has to be created first
img.save(path + '/tiff/' + pre + ext)