Commit 4cc032b8 authored by Matthijs's avatar Matthijs
Browse files

scikit-image rather than imageio

parent f60613ab
import numpy as np import numpy as np
import numpy.fft as fft
from scipy.io import loadmat from scipy.io import loadmat
from scipy.ndimage import binary_dilation from scipy.ndimage import binary_dilation
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import imageio from skimage.io import imread
from proxtoolbox.Utilities.OrbitalTomog.binning import bin_2d_array from proxtoolbox.Utilities.OrbitalTomog.binning import bin_2d_array
from proxtoolbox.Utilities.OrbitalTomog.array_tools import shifted_ifft, shifted_fft from proxtoolbox.Utilities.OrbitalTomog.array_tools import shifted_ifft, shifted_fft
...@@ -12,17 +11,18 @@ def data_processor(config): ...@@ -12,17 +11,18 @@ def data_processor(config):
if config['data_filename'][1] == ':': if config['data_filename'][1] == ':':
path_to_file = config['data_filename'] path_to_file = config['data_filename']
else: else:
path_to_file = '../../../InputData/OrbitalTomog/' + config['data_filename'] path_to_file = '../../../../InputData/OrbitalTomog/' + config['data_filename']
try: try:
if config['data_filename'][-4:] == '.mat': # for the old coronene simulations by W. Bennecke if config['data_filename'][-4:] == '.mat': # for the old coronene simulations by W. Bennecke
inp_data = loadmat(path_to_file) inp_data = loadmat(path_to_file)
inp = inp_data["I2"] inp = inp_data["I2"]
else: else:
inp = imageio.imread(path_to_file) inp = imread(path_to_file)
except FileNotFoundError: except FileNotFoundError:
print("Tried path %s, found nothing. "% path_to_file)
path_to_file = input('Please enter the path to the datafile: ') path_to_file = input('Please enter the path to the datafile: ')
inp = imageio.imread(path_to_file) inp = imread(path_to_file)
ny, nx = inp.shape ny, nx = inp.shape
config['data'] = abs(inp) config['data'] = abs(inp)
...@@ -51,7 +51,7 @@ def data_processor(config): ...@@ -51,7 +51,7 @@ def data_processor(config):
# Object support determination # Object support determination
try: try:
config['support'] = imageio.imread(config['support_filename']) config['support'] = imread(config['support_filename'])
except KeyError: # 'support filename does not exist, so define a support here' except KeyError: # 'support filename does not exist, so define a support here'
if 'threshold for support' not in config: if 'threshold for support' not in config:
config['threshold for support'] = 0.1 config['threshold for support'] = 0.1
...@@ -71,7 +71,7 @@ def data_processor(config): ...@@ -71,7 +71,7 @@ def data_processor(config):
# Autocorrelation # Autocorrelation
config['threshold for support'] = 0.1 config['threshold for support'] = 0.1
autocorrelation = abs(fft.fftshift(fft.ifft2(fft.ifftshift(inp)))) autocorrelation = abs(shifted_ifft(inp))
config['abs_illumination'] = np.ones_like(config['support']) config['abs_illumination'] = np.ones_like(config['support'])
# Initial guess # Initial guess
...@@ -81,8 +81,7 @@ def data_processor(config): ...@@ -81,8 +81,7 @@ def data_processor(config):
if ('use_sparsity_with_support' in config if ('use_sparsity_with_support' in config
and config['use_sparsity_with_support'] and config['use_sparsity_with_support']
and 'sparsity_support' not in config): and 'sparsity_support' not in config):
ac = abs(fft.fftshift(fft.ifft2(fft.ifftshift(inp)))) config['sparsity_support'] = binary_dilation(autocorrelation > 0.01 * np.amax(autocorrelation)).astype(np.uint)
config['sparsity_support'] = binary_dilation(ac > 0.01 * np.amax(ac)).astype(np.uint)
if config['dataprocessor_plotting']: if config['dataprocessor_plotting']:
plt.figure(figsize=(15, 4)) plt.figure(figsize=(15, 4))
...@@ -110,55 +109,6 @@ def data_processor(config): ...@@ -110,55 +109,6 @@ def data_processor(config):
return config return config
#
# def bin_2d_array(arr, new_shape):
# """"
# bins a 2D numpy array
# Args:
# arr: input array to be binned
# new_shape: shape after binning
# Returns:
# binned np array
# """
# shape = (new_shape[0], arr.shape[0] // new_shape[0],
# new_shape[1], arr.shape[1] // new_shape[1])
# if np.any(np.isnan(arr)):
# binfactor = 1
# for i, s in enumerate(arr.shape):
# binfactor *= new_shape[i] / s
# return np.nanmean(arr.reshape(shape), axis=(3, 1)) * binfactor
# else:
# return arr.reshape(shape).sum(-1).sum(1)
# def shifted_fft(arr, axes=None):
# """
# Combined fftshift and fft routine, based on scipy.fftpack
#
# Args:
# arr: numpy array
# axes: identical to argument for scipy.fftpack.fft
#
# Returns:
# transformed array
# """
#
# return fft.ifftshift(fft.fftn(fft.fftshift(arr, axes=axes), axes=axes), axes=axes)
#
#
# def shifted_ifft(arr, axes=None):
# """
# Combined fftshift and fft routine, based on scipy.fftpack
#
# Args:
# arr: numpy array
# axes: identical to argument for scipy.fftpack.fft
#
# Returns:
# transformed array
# """
# return fft.fftshift(fft.ifftn(fft.ifftshift(arr, axes=axes), axes=axes), axes=axes)
def support_from_autocorrelation(input_array: np.ndarray, def support_from_autocorrelation(input_array: np.ndarray,
threshold: float = 0.1, threshold: float = 0.1,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment