This repository was archived by the owner on Nov 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_main.py
More file actions
223 lines (182 loc) · 7.11 KB
/
Copy pathGUI_main.py
File metadata and controls
223 lines (182 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import numpy as np
import rawpy
from PIL import Image
import cv2
from tkinter import *
from tkinter import filedialog
from tkinter import ttk
from combination_algos import *
from gamma_correction import *
from os import listdir
from os.path import isfile, join
from alignment import *
### REMARK: Please only place RAW image files in the selected directory ###
def perform_stacking():
global base_path
global algorithm_index
global label_error
global resolution_scaler
if label_error:
label_error.destroy()
if algorithm_index == 0:
print('SELECT ALGO')
label_error = Label(gui, text="ERROR no algorithm selected!", fg="red")
label_error.grid(column=0, row=5)
return
if base_path == '':
print('SELECT basepath')
label_error = Label(gui, text="ERROR no base path selected!", fg="red")
label_error.grid(column=0, row=5)
return
image_paths = [f for f in listdir(base_path) if isfile(join(base_path, f))]
rgb_vec = []
for path in image_paths:
raw = rawpy.imread(base_path + '/' + path)
rgb = raw.postprocess(use_camera_wb=True, no_auto_bright=True)
print(rgb.shape)
rgb_vec.append(rgb)
h = rgb_vec[0].shape[0]
w = rgb_vec[0].shape[1]
print(f'w:{w}')
print(f'h:{h}')
total_images = len(rgb_vec)
print(f'total_images:{total_images}')
# for the alignment we use the grayscale image
# base_gray = np.dot(rgb_vec[0][..., :3], [0.299, 0.587, 0.114])
# for i in range(1,total_images):
# # M = match(rgb_vec[0], rgb_vec[i])
# # rgb = cv2.warpPerspective(rgb_vec[i], M, (w, h))
# gray_im = np.dot(rgb_vec[i][...,:3], [0.299, 0.587, 0.114])
# rgb = alignImages(base_gray, gray_im)
# img = Image.fromarray(rgb)
# img.show()
scaler = int(resolution_scaler.get())
print(f'resolution_scaler.get(): {scaler}')
base_image = rgb_vec[0]
img = Image.fromarray(base_image[0:h // scaler, 0:w // scaler])
img.show() # The base image
rgb = combination_alogs(rgb_vec, ALGO(algorithm_index), scaler)
# print(rgb)
img = Image.fromarray(rgb)
img.show()
## Used to indicate how we would implement the alignment code (doesn't work) ##
def perform_stacking_broken_alignment():
global base_path
global algorithm_index
global label_error
global resolution_scaler
if label_error:
label_error.destroy()
if algorithm_index == 0:
print('SELECT ALGO')
label_error = Label(gui, text="ERROR no algorithm selected!", fg="red")
label_error.grid(column=0, row=5)
return
if base_path == '':
print('SELECT basepath')
label_error = Label(gui, text="ERROR no base path selected!", fg="red")
label_error.grid(column=0, row=5)
return
image_paths = [f for f in listdir(base_path) if isfile(join(base_path, f))]
rgb_vec = []
for path in image_paths:
print(f'path: {path}')
raw = rawpy.imread(base_path + '/' + path)
rgb = raw.postprocess(use_camera_wb=True, no_auto_bright=True)
print(rgb.shape)
rgb_vec.append(rgb)
rgb = rgb_vec[0]
img = Image.fromarray(rgb)
img.show() # The base image
#Implement chunking
h = rgb_vec[0].shape[0]
w = rgb_vec[0].shape[1]
print(f'w:{w}')
print(f'h:{h}')
N = 50
total_images = len(rgb_vec)
print(f'total_images:{total_images}')
scaler = int(resolution_scaler.get())
print(f'resolution_scaler.get(): {scaler}')
rgb = np.zeros([w,h,3], dtype=np.uint8)
for x_c in range(N-1):
for y_c in range(N-1):
print(f'percentage: {(y_c + x_c*N)/(N*N)*100}%')
rgb_vec_split = []
for i in range(len(rgb_vec)):
start_x = x_c*(w//N)
stop_x = (x_c+1)*(w//N)
start_y = y_c*(h//N)
stop_y = (y_c+1)*(h//N)
rgb_vec_split.append(rgb_vec[i][start_x:stop_x,start_y:stop_y,:])
# for the alignment we use the grayscale image
# base_gray = np.dot(rgb_vec[0][..., :3], [0.299, 0.587, 0.114])
# for i in range(1,total_images):
# # M = match(rgb_vec[0], rgb_vec[i])
# # rgb = cv2.warpPerspective(rgb_vec[i], M, (w, h))
# gray_im = np.dot(rgb_vec[i][...,:3], [0.299, 0.587, 0.114])
# rgb = alignImages(base_gray, gray_im, rgb_vec[i])
# img = Image.fromarray(rgb)
# img.show()
rgb[start_x:stop_x,start_y:stop_y-1,:] = combination_alogs(rgb_vec_split, ALGO(algorithm_index), scaler, 1)
# raw = rawpy.imread('data/New/IMG_0702.CR2')
# rgb_im = raw.postprocess(use_camera_wb=True, no_auto_bright=True)#no_auto_scale=True)#, no_auto_bright=True)
# print(rgb_im)
# print(rgb_im.shape)
# img = Image.fromarray(rgb_im)
# img.show()
# equal_im = noise_equal(rgb_im)
#
# print(equal_im)
# print(rgb_im.shape)
# print(equal_im.shape)
# img2 = Image.fromarray(equal_im)
# img2.show()
img = Image.fromarray(rgb)
img.show()
def directory():
# get a directory path by user
global base_path
global label_path
filepath = filedialog.askdirectory(initialdir=r"C:\python\pythonProject", title="Dialog box")
print(f'filepath: {filepath}')
if filepath != ():
base_path = filepath
if label_path:
label_path.destroy()
label_path = Label(gui, text="Selected directory: " + filepath)
label_path.grid(column=0, row=4, columnspan = 2)
# Function to get the index of selected option in Combobox
def callback_algo(*args):
global algorithm_index
algorithm_index = cb.current() + 1
print(f'algorithm_index:{algorithm_index}')
if __name__ == '__main__':
gui = Tk()
gui.title('The image stacker 9001')
gui.geometry('800x200')
base_path = '' # empty string to init
label_path = None
label_error = None
algorithm_index = 0 # 0 to init
resolution_scaler = IntVar()
dir_button = Button(gui, text='select image directory', command=directory)
dir_button.grid(column=0, row=3)
# Define Options Tuple
options = ('No rejection', 'Median', 'MINMAX', 'Sigma Clipping', 'Average Sigma Clipping', 'No weight, no rejection', 'Turkey\'s Biweight')
var = StringVar()
var.set('Select stacking algorithm of choice')
cb = ttk.Combobox(gui, textvariable=var)
cb['values'] = options
cb.grid(column=0, row=0)
# Set the tracing for the given variable
var.trace('w', callback_algo)
options2 = (1,2,4,8,16,32)
label_res = Label(gui, text="Axial resolution devisor (default=1 i.e. no scaling, 2 --> 1/4 = 1/(2*2) as many pixels)")
label_res.grid(column=0, row=1, columnspan = 2)
resolution_scaler = ttk.Combobox(gui, values = options2)
resolution_scaler.current(0)
resolution_scaler.grid(column=0, row=2)
start_button = Button(gui, text='start stacking', command=perform_stacking)
start_button.grid(column=1, row=3)
gui.mainloop()