Commit d1e39d38 authored by jansen31's avatar jansen31
Browse files

sparsity with support possibility

parent cb1c5e6f
......@@ -18,7 +18,7 @@ new_config = {
# Options are: 'support only', 'real and support', 'nonnegative and support',
# 'amplitude only', 'sparse real', 'sparse complex', and 'hybrid'
# 'symmetric sparse real', 'symmetric sparse complex'
'constraint': 'real and support',
'constraint': 'sparse real',
# What type of measurements are we working with?
# Options are: 'single diffraction', 'diversity diffraction',
......@@ -99,6 +99,11 @@ new_config = {
'beta_switch': 30, # iteration at which beta moves from beta_0 -> beta_max
'lambda_switch': 100,
'sparsity_parameter': 16,
'use_sparsity_with_support': False,
'symmetry_type': 1, # -1 for antisymmetric functions, 1 for symmetric ones.
'symmetry_axis': -1, # which axis is symmetric. (mirror plane perpendicular to this axis)
# parameter for the data regularization
# need to discuss how/whether the user should
# put in information about the noise
......@@ -148,8 +153,8 @@ new_config = {
# default is 1.
'graphics_display': 'Phase_graphics', # name of the plotting routine
'dataprocessor_plotting': True,
'interpolate_result': True
'interpolate_result': True,
'zoomin_on_result': True
}
......
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 imageio
......@@ -28,6 +29,12 @@ def data_processor(config):
ph_init = 2 * np.pi * np.random.rand(ny, nx)
config['u_0'] = inp * np.exp(1j * ph_init)
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)
if config['dataprocessor_plotting']:
plt.figure(figsize=(15, 4))
plt.subplot(131)
......
......@@ -165,6 +165,9 @@ class Phase(Problem):
# This sequence will work for objects *with a small support* even if they lie over the edge of the array
if 'interpolate_result' in self.config and self.config['interpolate_result']:
self.output[key] = Graphics.fourier_interpolate(self.output[key])
if 'zoomin_on_result' in self.config and self.config['zoomin_on_result']:
zmy, zmx = int(self.config['Ny'] / 4), int(self.config["Nx"] / 4)
self.output[key] = self.output[key][zmy:-zmy, zmx:-zmx]
def show(self):
"""
......
......@@ -33,6 +33,11 @@ class P_Sparsity(ProxOperator):
self.sparsity_parameter = config['sparsity_parameter']
self.ny = config['Ny']
if 'sparsity_support' in config:
self.support = config['sparsity_support'].real.astype(np.uint)
else:
self.support = 1
if self.sparsity_parameter > 30:
def value_selection(original, indices, sparsity_parameter):
idx_for_threshold = divmod(indices[-sparsity_parameter], self.ny)
......@@ -59,10 +64,10 @@ class P_Sparsity(ProxOperator):
-------
p_Sparsity : array_like
"""
sparsity_parameter = self.sparsity_parameter
u *= self.support # apply support
p_Sparsity = 0 * u
sorting = np.argsort(abs(u), axis=None) # gives indices of sorted array in ascending order
indices = np.asarray([divmod(sorting[i], self.ny) for i in range(-1 * sparsity_parameter, 0)])
indices = np.asarray([divmod(sorting[i], self.ny) for i in range(-1 * self.sparsity_parameter, 0)])
p_Sparsity[indices[:, 0], indices[:, 1]] = u[indices[:, 0], indices[:, 1]]
return p_Sparsity
......@@ -79,8 +84,8 @@ class P_Sparsity_real(P_Sparsity):
class P_Sparsity_Symmetric(P_Sparsity):
def __init__(self, config):
super(P_Sparsity_Symmetric, self).__init__(config=config)
self.symmetry = config['symmetry type'] # antisymmetric = -1, symmetric = 1
self.symmetry_axis = config['symmetry axis'] # -1 for last, 0 for first, 'both', 'all' or None for full flip
self.symmetry = config['symmetry_type'] # antisymmetric = -1, symmetric = 1
self.symmetry_axis = config['symmetry_axis'] # -1 for last, 0 for first, 'both', 'all' or None for full flip
def work(self, u):
if self.symmetry_axis in ['both', 'all']:
......
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