From c7ac34437105e333523469bc76e727004aaacf46 Mon Sep 17 00:00:00 2001 From: "Knollmueller, Jakob (kjako)" Date: Wed, 14 Feb 2018 16:58:18 +0100 Subject: [PATCH] additional separations added --- 1d_separation.py | 108 ++++++++++++++++++++++++++++++++++++++++++++ gui_app.py | 2 +- point_separation.py | 34 +++++++++++--- rgb_separation.py | 24 ++++++++++ 4 files changed, 160 insertions(+), 8 deletions(-) create mode 100644 1d_separation.py create mode 100644 rgb_separation.py diff --git a/1d_separation.py b/1d_separation.py new file mode 100644 index 0000000..d470c5c --- /dev/null +++ b/1d_separation.py @@ -0,0 +1,108 @@ +from point_separation import build_problem, problem_iteration +from nifty2go import * +import numpy as np +from matplotlib import rc +rc('font',**{'family':'serif','serif':['Palatino']}) +rc('text', usetex=True) +from matplotlib import pyplot as plt + +np.random.seed(42) +if __name__ == '__main__': + s_space = RGSpace([1024]) + FFT = FFTOperator(s_space) + h_space = FFT.target[0] + p_space = PowerSpace(h_space) + sp = Field(p_space, val=1./(1+p_space.k_lengths)**2.5 ) + sh = power_synthesize(sp) + s = FFT.adjoint_times(sh) + + u = Field(s_space, val = -12) + u.val[200] = 1 + u.val[300] = 3 + u.val[500] = 4 + u.val[700] = 5 + u.val[900] = 2 + u.val[154] = 0.5 + u.val[421] = 0.25 + u.val[652] = 1 + u.val[1002] = 2.5 + + d = exp(s) + exp(u) + data = d.val + + energy1 = build_problem(data,1.25) + energy2 = build_problem(data,1.5) + energy3 = build_problem(data,1.75) + + for i in range(20): + energy1 = problem_iteration(energy1) + energy2 = problem_iteration(energy2) + energy3 = problem_iteration(energy3) + + plt.figure() + # plt.plot(data, 'k-') + f, (ax0, ax1,ax2) = plt.subplots(3, sharex=True, sharey=True) + plt.suptitle('diffuse components') + + ax0.plot(exp(energy1.s).val, 'k-') + ax0.yaxis.set_label_position("right") + ax0.set_ylabel(r'$\alpha = 1.25$') + ax0.set_ylim(1e-1,1e3) + ax0.set_yscale("log") + + ax1.plot(exp(energy2.s).val, 'k-') + ax1.yaxis.set_label_position("right") + ax1.set_ylabel(r'$\alpha = 1.5$') + + ax2.plot(exp(energy3.s).val, 'k-') + ax2.yaxis.set_label_position("right") + ax2.set_ylabel(r'$\alpha = 1.75$') + + plt.savefig('1d_diffuse.pdf') + + plt.figure() + f, (ax0, ax1,ax2) = plt.subplots(3, sharex=True, sharey=True) + + plt.suptitle('point-like components') + + ax0.plot(exp(energy1.u).val, 'k-') + ax0.yaxis.set_label_position("right") + ax0.set_ylabel(r'$\alpha = 1.25$') + ax0.set_ylim(1e-1,1e3) + ax0.set_yscale("log") + + ax1.plot(exp(energy2.u).val, 'k-') + ax1.yaxis.set_label_position("right") + ax1.set_ylabel(r'$\alpha = 1.5$') + + ax2.plot(exp(energy3.u).val, 'k-') + ax2.yaxis.set_label_position("right") + ax2.set_ylabel(r'$\alpha = 1.75$') + + ax0.set_yscale("log") + + ax0.set_ylim(1e-1,1e3) + + # plt.ylim(1e-0) + plt.savefig('1d_points.pdf') + plt.figure() + f, (ax0, ax1,ax2) = plt.subplots(3, sharex=True, sharey=True) + plt.suptitle('data and true components') + + ax0.plot(data, 'k-') + ax0.set_yscale("log") + ax0.set_ylim(1e-1,1e3) + ax0.yaxis.set_label_position("right") + ax0.set_ylabel(r'data') + + + ax1.plot(exp(s).val, 'k-') + ax1.yaxis.set_label_position("right") + ax1.set_ylabel(r'diffuse') + ax2.plot(exp(u).val, 'k-') + ax2.yaxis.set_label_position("right") + ax2.set_ylabel(r'point-like') + + # plt.ylim(1e-0) + plt.savefig('1d_data.pdf') + diff --git a/gui_app.py b/gui_app.py index 574b236..4378f5d 100644 --- a/gui_app.py +++ b/gui_app.py @@ -173,7 +173,7 @@ class SeparatorApp(App): self.diffuse_image = self.result_path + 'diffuse.png' def plot_array(self, array, path): - plt.imsave(path, np.exp(array), vmin=self.vmin, vmax=self.vmax) + plt.imsave(path, array, vmin=self.vmin, vmax=self.vmax) def set_alpha(self, alpha): diff --git a/point_separation.py b/point_separation.py index fadb91d..d2dcc66 100644 --- a/point_separation.py +++ b/point_separation.py @@ -17,7 +17,7 @@ def load_data(path): return data def build_problem(data, alpha): - s_space = RGSpace(data.shape, distances=[1, 1]) + s_space = RGSpace(data.shape, distances=len(data.shape) * [1]) data = Field(s_space,val=data) FFT = FFTOperator(s_space) h_space = FFT.target[0] @@ -55,22 +55,42 @@ def problem_iteration(energy): new_energy = SeparationEnergy(new_position, new_parameters) return new_energy +def build_multi_problem(data, alpha): + energy_list = [] + for i in range(data.shape[-1]): + energy = build_problem(data[...,i],alpha) + energy_list.append(energy) + return energy_list + +def multi_problem_iteration(energy_list): + new_energy = [] + for energy in energy_list: + new_energy.append(problem_iteration(energy)) + return new_energy + if __name__ == '__main__': path = 'hst_05195_01_wfpc2_f702w_pc_sci.fits' data = load_data(path) - alpha = 1.5 + alpha = 1.3 myEnergy = build_problem(data, alpha=alpha) - + x =np.arange(0,100) + y = np.sin(x/12.) + y **=2 + y[50] = 10 + y[4] = 5 + y[70] = 3 + y += 0.1 + myEnergy = build_problem(y, alpha=alpha) for i in range( 100): myEnergy = problem_iteration(myEnergy) - plt.viridis() - plt.imsave('points0.png',myEnergy.u.val) - plt.imsave('maps0.png',(myEnergy.s).val) - plt.imsave('data0.png',myEnergy.d.val) + # plt.viridis() + # plt.imsave('points0.png',myEnergy.u.val) + # plt.imsave('maps0.png',(myEnergy.s).val) + # plt.imsave('data0.png',myEnergy.d.val) diff --git a/rgb_separation.py b/rgb_separation.py new file mode 100644 index 0000000..d58ed86 --- /dev/null +++ b/rgb_separation.py @@ -0,0 +1,24 @@ +from point_separation import build_multi_problem, multi_problem_iteration +from matplotlib import pyplot as plt +import numpy as np + +if __name__ == '__main__': + data = plt.imread('eso1242a.jpg') + data = data.astype(float) + data = data.clip(0.0001) + energy_list = build_multi_problem(data, 1.35) + + for i in range(10): + energy_list = multi_problem_iteration(energy_list) + + + diffuse = np.empty_like(data) + point = np.empty_like(data) + for i in range(len(energy_list)): + diffuse[...,i] = np.exp(energy_list[i].s.val) + point[...,i] = np.exp(energy_list[i].u.val) + + plt.imsave('rgb_diffuse.jpg',diffuse/255.) + plt.imsave('rgb_point.jpg',point/255.) + + -- GitLab