Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
4cc032b8
Commit
4cc032b8
authored
Apr 22, 2020
by
Matthijs
Browse files
scikit-image rather than imageio
parent
f60613ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/Problems/OrbitalTomog/planar_molecule/orbitaltomog_data_processor.py
View file @
4cc032b8
import
numpy
as
np
import
numpy.fft
as
fft
from
scipy.io
import
loadmat
from
scipy.ndimage
import
binary_dilation
import
matplotlib.pyplot
as
plt
import
im
ageio
from
skimage.io
import
im
read
from
proxtoolbox.Utilities.OrbitalTomog.binning
import
bin_2d_array
from
proxtoolbox.Utilities.OrbitalTomog.array_tools
import
shifted_ifft
,
shifted_fft
...
...
@@ -12,17 +11,18 @@ def data_processor(config):
if
config
[
'data_filename'
][
1
]
==
':'
:
path_to_file
=
config
[
'data_filename'
]
else
:
path_to_file
=
'../../../InputData/OrbitalTomog/'
+
config
[
'data_filename'
]
path_to_file
=
'../../../
../
InputData/OrbitalTomog/'
+
config
[
'data_filename'
]
try
:
if
config
[
'data_filename'
][
-
4
:]
==
'.mat'
:
# for the old coronene simulations by W. Bennecke
inp_data
=
loadmat
(
path_to_file
)
inp
=
inp_data
[
"I2"
]
else
:
inp
=
imageio
.
imread
(
path_to_file
)
inp
=
imread
(
path_to_file
)
except
FileNotFoundError
:
print
(
"Tried path %s, found nothing. "
%
path_to_file
)
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
config
[
'data'
]
=
abs
(
inp
)
...
...
@@ -51,7 +51,7 @@ def data_processor(config):
# Object support determination
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'
if
'threshold for support'
not
in
config
:
config
[
'threshold for support'
]
=
0.1
...
...
@@ -71,7 +71,7 @@ def data_processor(config):
# Autocorrelation
config
[
'threshold for support'
]
=
0.1
autocorrelation
=
abs
(
fft
.
fftshift
(
fft
.
ifft2
(
fft
.
ifftshi
ft
(
inp
))
))
autocorrelation
=
abs
(
shifted_if
ft
(
inp
))
config
[
'abs_illumination'
]
=
np
.
ones_like
(
config
[
'support'
])
# Initial guess
...
...
@@ -81,8 +81,7 @@ def data_processor(config):
if
(
'use_sparsity_with_support'
in
config
and
config
[
'use_sparsity_with_support'
]
and
'sparsity_support'
not
in
config
):
ac
=
abs
(
fft
.
fftshift
(
fft
.
ifft2
(
fft
.
ifftshift
(
inp
))))
config
[
'sparsity_support'
]
=
binary_dilation
(
ac
>
0.01
*
np
.
amax
(
ac
)).
astype
(
np
.
uint
)
config
[
'sparsity_support'
]
=
binary_dilation
(
autocorrelation
>
0.01
*
np
.
amax
(
autocorrelation
)).
astype
(
np
.
uint
)
if
config
[
'dataprocessor_plotting'
]:
plt
.
figure
(
figsize
=
(
15
,
4
))
...
...
@@ -110,55 +109,6 @@ def data_processor(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
,
threshold
:
float
=
0.1
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment