-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_PhotoBleaching.jl
607 lines (528 loc) · 21.5 KB
/
3_PhotoBleaching.jl
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
### A Pluto.jl notebook ###
# v0.19.9
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ fadf633b-621f-4f18-bbb5-df18273d2e6c
using Pkg; Pkg.activate("C:\\Users\\Alfonso\\MEGA\\PhD\\BOLD\\Data_analysis\\WideField_analysis")
# ╔═╡ 3eac8dee-8709-4ed1-8fc4-ad163f1f5426
begin
using Images
using Plots
using Plots.PlotMeasures
using LaTeXStrings
using PlutoUI
using Base.Filesystem
using DelimitedFiles
using CSV
using Colors
using FixedPointNumbers
using Statistics
using Revise
using StatsBase
using DataFrames
using SpecialFunctions
using EasyFit
gr();
end
# ╔═╡ 3afbafe0-1371-11ef-0114-3b191c3f6904
md"""
# Program explanation
"""
# ╔═╡ 40b08f2f-2bfd-4601-9ae5-18b199fce144
md"""
This notebook takes data from a field on a sample and the ROI selected in the spectrum analysis (notebooks 1 and 2). Then, it processes the data inside the ROI (binning and deconvolve functions, chosen by the user), applies AutoStepFinder in the arrays containing the temporal evolution of every pixel inside the ROI and stores the results, that can be processed together with other fields with notebook 4.
"""
# ╔═╡ 78f03196-450c-4c51-afc3-5a664b81fef3
md"""
## Set the working directory
"""
# ╔═╡ 5b03b13c-a813-4916-b13e-08413b370670
folder_data = raw"C:\Users\Alfonso\BOLD\WideField\Data\april_2024\60\PB\Field3"
# ╔═╡ 7b076d68-ebc9-447e-bde2-815036a3e3d4
acquisition_rate = 0.5; #in seconds, time between frame acquisition
# ╔═╡ 3bc06e36-0692-4f85-83f8-a1a38c0d9ace
md"""
## Read ROI from spectrum analysis
"""
# ╔═╡ 6adf724f-73ad-424d-a0cb-2869ce73c3d8
begin
field_number = basename(folder_data)
spectra_folder = joinpath(dirname(dirname(folder_data)), "Spectrum", field_number)
if isdir(joinpath(spectra_folder, "Analysis_AYN"))
if isfile(joinpath(spectra_folder, "Analysis_AYN", "ROI.txt"))
roi_string = read(joinpath(spectra_folder, "Analysis_AYN", "ROI.txt"), String)
roi = [parse(Int, val) for val in split(roi_string)]
else
println("Spectra analysis folder does not exist, analyze the spectrum before PB")
end
else
println("Spectra analysis folder does not exist, analyze the spectrum before PB")
end
end;
# ╔═╡ 47c48ee0-ca8e-4f58-8fc8-17489d707ff0
md"""
Check to perform data processing before applying AutoStepFinder algorithm: $(@bind preprocess CheckBox())
"""
# ╔═╡ 6ed429a2-41f6-4fa4-8ecb-b39742aa4547
if preprocess
println("Set the value of binsize, lambda and aperture diameter")
binsize = 4
lambda = 450
aperture_diameter = 2
end;
# ╔═╡ db148fe2-143a-49f1-a4bc-10cf7599ea01
md"""
Set parameters for AutoStepFinder:
"""
# ╔═╡ 1fc5a82f-9d59-4fb1-a8f3-fde719bfd20d
begin
tresH = 0.1
N_iter = 50
end;
# ╔═╡ 0bef7c1e-c14d-4455-951b-d30e206dbdfb
begin
data = readdir(folder_data)
num_files = count(endswith(".tif"), data) - 1
end;
# ╔═╡ 34a8690e-8ccd-4b4a-8547-b6b73ead33a9
md"""
# Sets of frames analysis. Statistics
"""
# ╔═╡ a635d61d-4ea2-4c90-9237-8d3668de740b
max_pixels_to_store = 500; #Sets the maximum number of pixels that the program will store if they pass the algorithm (to avoid huge size of data storage)
# ╔═╡ bdc51e2e-21e9-404d-84de-bd776192ecae
md"""
Check to analyze all images of field (time consuming) and store results: $(@bind temp_evol CheckBox())
"""
# ╔═╡ a189b589-cc79-4736-a345-0a3d28f23cca
md"""
# Individual pixel trajectories
"""
# ╔═╡ 0063fa47-f32f-4302-bd66-55e6e0a05a03
md"""
##### Fit of the photobleaching to an exponential
"""
# ╔═╡ 8754abf0-df80-4c2f-9ad7-84350e5161ee
seconds_to_fit = 100; #temporal limit of the fit in seconds
# ╔═╡ bbbf0b41-746c-4f01-a1e9-dee2bdbeab48
md"""
##### Plots
"""
# ╔═╡ fef0fc51-3c44-4c00-bad9-acbff5df6cf4
md"""
Check to store the trajectories of all active pixels: $(@bind store_trajectories CheckBox())
"""
# ╔═╡ ca58450a-8f5b-4b48-8dff-f370a7d640f9
md"""
##### Creation of the results folder (if not existent) and storage of results
"""
# ╔═╡ 21e6bd2b-ee27-4db4-aa5f-09e95deab2c4
md"""# Functions"""
# ╔═╡ 0bc1224b-5a4f-4f6e-a668-0dcec4a1fc7e
"""
Imports the .jl documents from the given location
"""
function Ingredients(path::String)
# this is from the Julia source code (evalfile in base/loading.jl)
# but with the modification that it returns the module instead of the last object
name = Symbol(basename(path))
m = Module(name)
Core.eval(m,
Expr(:toplevel,
:(eval(x) = $(Expr(:core, :eval))($name, x)),
:(include(x) = $(Expr(:top, :include))($name, x)),
:(include(mapexpr::Function, x) = $(Expr(:top, :include))(mapexpr, $name, x)),
:(include($path))))
m
end
# ╔═╡ 12322533-ce10-4382-b527-97ac8c54d6ea
asf = Ingredients("..\\src\\AutoStepFinder.jl")
# ╔═╡ 2a5ee74c-e17b-4088-b4d2-0c3f51dcb50b
"""
Returns an array with the data from image n in the file folder
"""
function Get_Image(folder, frame)
nstr = lpad(string(frame), 5, '0')
files = readdir(folder)
sort!(files)
filename = filter(file -> occursin(nstr, file[end-9:end-4]), files)
full_path = joinpath(folder, filename[end])
#print(full_path) #debug, prints the resulting path of the image to be acquired
image = Images.load(full_path)
image_data = reinterpret(UInt16, channelview(image))
image_array = Float64.(channelview(image_data))
return image_array
end
# ╔═╡ 137fbbfa-a807-4137-a3bc-f52899ea6e2f
"""
Main function that uses the core processes from AutoStepFinder to return S_curve, best_shots, final fits and the table with steps
"""
function AutoStepMain(data_to_analyze, tresH, N_iter)
Fit = zeros(size(data_to_analyze))
newFit, _, _, S_curve, best_shot = asf.AutoStepFinder.stepfindcore(data_to_analyze, tresH, N_iter)
Fit = asf.AutoStepFinder.AppendFitX(newFit, Fit, data_to_analyze)
step_table = asf.AutoStepFinder.fit2Steps(data_to_analyze, Fit)
return S_curve, best_shot, Fit, step_table
end
# ╔═╡ 5211e6b5-b445-4a67-980e-70a2a86cbc31
"""
Processes the outputs from AutoStepMain and builds histograms with the resulting steps for the pixels that pass the algorithm (active_pixels)
"""
function Get_Histograms_ROI(temporal_evolution, tresH, N_iter)
hist_heights = Vector{Any}()
hist_widths = Vector{Any}()
n_steps = Vector{Int}()
I, J = size(temporal_evolution[1]) #Size of the ROI, taken from the first frame
active_pixels = reshape([], 0, 2)
for i in 1:I
for j in 1:J
pixel_evolution = [temporal_evolution[k][i, j] for k in 1:length(temporal_evolution)] #We construct an array containing the intensity data of the same pixel over all the frames (temporal evolution of the pixel)
S_curve, best_shot, Fit, steptable = AutoStepMain(pixel_evolution, tresH, N_iter)
if best_shot > 0 && S_curve[best_shot] > tresH
LST = size(steptable)[1]
if LST > 2
push!(n_steps, size(steptable, 1))
push!(hist_heights, steptable[1:LST, 4])
push!(hist_widths, cumsum(steptable[1:LST, 5]))
active_pixels = [active_pixels; [j i]]
end
end
end
end
hw = vcat(hist_widths...)
hh = vcat(hist_heights...)
sorting_indices = sortperm(active_pixels[:, 1])
sorted_active_pixels = active_pixels[sorting_indices, :]
return hh, hw, n_steps, sorted_active_pixels
end
# ╔═╡ 627ff63b-2e22-4b04-a81d-3816764159c9
"""
Calls the AutoStepFinder analysis functions, plots the results and returns plots and data
"""
function Analyze_Image(temporal_evolution, tresH)
hh, hw, n_steps, active_pixels = Get_Histograms_ROI(temporal_evolution, tresH, N_iter);
res_array = hh, hw, n_steps, active_pixels
#if all(n_steps .> 0)
# p1 = histogram(n_steps, label="Number of steps")
# p2 = histogram(hh, label="Step height")
# p3 = histogram(hw, label="Step width")
# phs = plot(p1, p2, p3, layout=(1,3))
#else
# @warn "No steps detected"
#end
p1 = histogram(n_steps, color=:blue, label = false, xlabel="Number of steps", xlabelfontsize = 10)
p2 = histogram(hh, color=:green, label = false, xlabel="Step height", xlabelfontsize = 10)
p3 = histogram(hw, color=:orange, label = false, xlabel="Step width", xlabelfontsize = 10)
phs = plot(p1, p2, p3, layout=(1,3))
return phs, res_array
end
# ╔═╡ bcdd5938-b934-4aa8-a416-40a70acb8540
"""
Stores results in a CSV file located in CSV_path
"""
function Store_Dataframe(active_pixels, n_steps, hh, hw, CSV_path)
ijsave = hcat(inverse_rle(active_pixels[:,1], n_steps), inverse_rle(active_pixels[:,2], n_steps)) #We are just interested in active pixels, so we create two columns with its coordinates
dfs = DataFrame(x=ijsave[:,1], y=ijsave[:,2], height=hh, width=hw) #We assign to the active pixels their corresponding step data
CSV.write(CSV_path, string.(dfs), header=true, append=true) #Creation of the CSV file
end
# ╔═╡ 478008c7-5e3c-486b-a8f8-ddc7daaaeecf
"""
Saves all the relevant results (CSV file through Store_Dataframe and graphs)
"""
function Save_Results(path, tresH, res_array, phs)
dirroot, fieldN = splitdir(path) #As path to store the results, we will use the same as that of the field data
dirres1 = joinpath(dirroot, "Analysis_AYN") #In case the field analyzed is the first in the folder, we create the results directory to use for all fields
try
mkdir(dirres1)
catch
@warn "Directory already exists"
end
dirres2 = joinpath(dirres1, fieldN) #We create a path to store the results with the number of the field analyzed
println(dirres2) #debug
try
mkdir(dirres2)
catch
@warn "Directory already exists. Field already analyzed"
end
filename = fieldN*".csv" #There will be a CSV file created for every field
path_results = joinpath(dirres2, filename);
print(path_results) #debug
header = " ", " ", "ROI position: $roi", "Threshold $tresH"
CSV.write(path_results, [header], header=false)
hh, hw, n_steps, active_pixels = res_array
Store_Dataframe(active_pixels, n_steps, hh, hw, path_results)
dirsave, filename = splitdir(path_results)
savefig(phs, joinpath(dirsave, fieldN*"hist.png")) #We also save the histogram figure of the field
return dirsave
end
# ╔═╡ f9962802-25fb-434e-8eaa-baae842af938
"""
Reads the temporal trajectories of the pixels passing the algorithm and fits them to exponential decays to obtain the photobleaching constant: tau
"""
function PhotoBleaching_Fit(temporal_evolution, active_pixels, seconds_to_fit)
fit_results_all = []
for i in 1:size(active_pixels)[1]
pixel_evolution = [temporal_evolution[k][active_pixels[i, 2], active_pixels[i, 1]] for k in 1:length(temporal_evolution)]
x = [a * acquisition_rate for a in 1:Int(seconds_to_fit/acquisition_rate)]
y = pixel_evolution[1:Int(seconds_to_fit/acquisition_rate)]
fit_results = fitexp(x, y)
push!(fit_results_all, fit_results)
end
return fit_results_all
end
# ╔═╡ 25c3886c-d10f-4918-888c-71755f73e193
md"""
# CURRENTLY IN DEVELOPMENT
"""
# ╔═╡ ff932c8a-ad5c-4748-96d8-d9987ea7c6b3
"""
Takes the data of a certain frame of the selected field and the size of the binning, then bins the data for the posterior analysis
"""
function Binning(unbinned_image, binsize)
binned_image = zeros(div(size(unbinned_image, 1), binsize), div(size(unbinned_image, 2), binsize))
for i in 1:binsize:size(unbinned_image, 1)
for j in 1:binsize:size(unbinned_image, 2)
print("$j ")
binned_image[div(i-1, binsize) + 1, div(j-1, binsize) + 1] = sum(unbinned_image[i:min(i + binsize - 1, end), j:min(j + binsize - 1, end)])
end
end
return binned_image
end
# ╔═╡ 1154c4ca-65d6-411a-9865-45d0cf37a902
"""
Creates and returns an array of matrices (temp_evol) containing the N successive temporal images of the roi of the field in the folder given
"""
function Temporal_Evolution(folder, N, roi)
if preprocess
println("Data will be processed before building the temporal evolution")
temp_evol = []
for i in 1:N
processed_frame = Binning(Get_Image(folder, i)[roi[1]:roi[2] - 1, roi[3]:roi[4] - 1], binsize)
#DECONVOLVE NEEDS TO BE REVISED
#binned_frame = Binning(Get_Image(folder, i)[roi[1]:roi[2] - 1, roi[3]:roi[4] - 1], binsize)
#processed_frame = Deconvolve_PSF(binned_frame, lambda, aperture_diameter)
push!(temp_evol, processed_frame)
end
else
println("Data will NOT be processed to build temporal evolution")
temp_evol = [Get_Image(folder, i)[roi[1]:roi[2] - 1, roi[3]:roi[4] - 1] for i in 1:N]
end
return temp_evol
end
# ╔═╡ 4896bcfe-fc29-4343-9433-7729dd70d2d0
evol_try = Temporal_Evolution(folder_data, 30, roi);
# ╔═╡ 073859fe-d83d-40bb-8cdb-ec1850e8ed1b
if temp_evol
figure = [heatmap(evol_try[i], c=:inferno, aspect_ratio=:equal, yflip=false, size=(600, 600)) for i=1:1];
end
# ╔═╡ a9570315-f705-4c41-8309-52d2ad8e0d9f
plot(figure...)
# ╔═╡ dd338429-8ea0-4404-9af3-74a133ac88d2
if temp_evol
println("Analyzing data in $folder_data")
temporal_evolution = Temporal_Evolution(folder_data, num_files, roi)
plots, results_array = Analyze_Image(temporal_evolution, tresH);
dirsave = Save_Results(folder_data, tresH, results_array, plots)
plot(plots)
end
# ╔═╡ 71f63fe1-bb8c-43ae-bb33-526199edc4ca
print("Algorithm passed by $(size(results_array[4], 1)) pixels")
# ╔═╡ 4060e35e-61f0-4121-83b8-df90fdca2408
photobleaching_fits = PhotoBleaching_Fit(temporal_evolution, results_array[4], seconds_to_fit);
# ╔═╡ f3b34417-8138-4948-a158-e38f169cfae0
begin
tau_values = [fit.b for fit in photobleaching_fits]
average_tau = mean(tau_values)
println("Average tau = $average_tau s")
end
# ╔═╡ 2f4b2a85-0aba-41ac-8c15-f9fafa26f35b
if store_trajectories && size(results_array[4])[1]< max_pixels_to_store
dirroot = dirname(folder_data)
results_folder_name = joinpath(dirroot, "Analysis_AYN")
if isdir(results_folder_name)
println("Parent directory already exists")
else
try
mkdir(results_folder_name)
println("Parent directory created")
catch e
println("Could not create directory")
end
end
subdirectory_field = joinpath(results_folder_name, field_number)
if isdir(subdirectory_field)
println("Subdirectory already exists")
else
try
mkdir(subdirectory_field)
println("Subdirectory created")
catch e
println("Could not create subdirectory")
end
end
directory_trajectories = joinpath(subdirectory_field, "Trajectories")
println(directory_trajectories)
if isdir(directory_trajectories)
println("Trajectory directory already exists")
else
try
mkdir(directory_trajectories)
println("Trajectory directory created")
catch e
println("Could not create trajectory directory")
end
end
else
if size(results_array[4])[1] >= max_pixels_to_store
println("More than $max_pixels_to_store active pixels. Set a higher value for the threshold or a higher value for \"max_pixels_to_store\"")
end
end
# ╔═╡ 904eab41-e58e-4625-8090-4fa39956be19
begin
frame = 10
figure_heatmap = "heatmap_frame_$(frame).png"
img = Get_Image(folder_data, frame)
p3 = heatmap(img, c=:inferno, aspect_ratio=:equal, yflip=false, size=(600, 600))
plot!([roi[1], roi[2], roi[2], roi[1], roi[1]], [roi[3], roi[3], roi[4], roi[4], roi[3]], seriestype=:shape, linecolor=:yellow, fillalpha=0., linealpha=0.9, linewidth=3, title=field_number*" at t = $(frame * acquisition_rate) s", titlefontsize = 12, label=false, widen=false, tickdirection=:out, margin=2mm)
savefig(joinpath(subdirectory_field, figure_heatmap));
end
# ╔═╡ e920f086-b0d4-4aa6-9e69-33bf24d137fa
p3
# ╔═╡ 14e2baff-6528-4f2f-a355-2b9279650144
"""
Analyzes and shows the desired pixel in the ROI and plots its temporal evolution together with the results of the AutoStepFinder analysis for it
"""
function Plot_Pixel_Trajectory(pixel, i, j, frame, tresH, N_iter, fit_results) #i, j are the coordinates of the pixel to analyze
pixel_evolution = [temporal_evolution[k][j, i] for k in 1:length(temporal_evolution)]
S_curve, best_shot, Fit, step_table = AutoStepMain(pixel_evolution, tresH, N_iter)
p1 = plot([i * acquisition_rate for i in 1:length(temporal_evolution)], pixel_evolution, label = "Evolution of ($i, $j)", xlabel = "t (s)", ylabel = "Pixel intensity value (a.u.)", xlabelfontsize = 10, ylabelfontsize = 10, linewidth=2)
if best_shot > 0 && S_curve[best_shot] > tresH
plot!([a * acquisition_rate for a in 1:length(temporal_evolution)], Fit, label = "ASF Fit", linewidth=2)
plot!([b * acquisition_rate for b in 1:length(fit_results[pixel].ypred)], fit_results[pixel].ypred, linewidth=2, label = L"\tau = " * string(round(fit_results[pixel].b, digits = 1)) * " s")
end
p2 = heatmap(frame, colorbar = false, c=:inferno, aspect_ratio=:equal, yflip=false)
xmin = i - 2
xmax = i + 2
ymin = j - 2
ymax = j + 2
plot!([xmin, xmax, xmax, xmin, xmin], [ymin, ymin, ymax, ymax, ymin], seriestype =:shape, linecolor =:white, fillalpha = 0., linealpha = 1.0, linewidth = 2, label="Pixel ($i, $j)")
final_plot = plot(p1, p2)
return final_plot
end
# ╔═╡ 7120159c-df13-4140-9add-f52c43530112
begin
pixel = 1
i = 44
j = 77
Plot_Pixel_Trajectory(pixel, i, j, temporal_evolution[1], tresH, N_iter, photobleaching_fits)
end
# ╔═╡ e3e900d6-3696-4b5d-b5f2-a74644dd0975
begin
plots_active_pixels = []
for pixel in 1:size(results_array[4])[1]
push!(plots_active_pixels, Plot_Pixel_Trajectory(pixel, results_array[4][pixel, 1], results_array[4][pixel, 2], temporal_evolution[1], tresH, N_iter, photobleaching_fits))
end
end
# ╔═╡ ecdc24c0-b4c4-43b8-8f08-3ac97e035686
plots_active_pixels[1]
# ╔═╡ 9af3cd4e-a16c-4f09-949d-5ac515e2f327
if store_trajectories
for i in 1:length(plots_active_pixels)
subplot = plot(plots_active_pixels[i])
savefig(joinpath(directory_trajectories, "Pixel_$i.png"))
end
end
# ╔═╡ 0b098090-12ab-4f8b-a9dc-3aaddb4d3b49
#CAREFUL HERE WITH THE ORDER OF I,J. CHECK
# ╔═╡ 971825d2-e532-4778-95dc-5092f2f94e19
"""
Defines the intensity of a pixel at a distance r due to the Airy disk for a given wavelength and aperture diameter
"""
function Airy_Disk(r, lambda, aperture_diameter)
k = 2 * pi / lambda
intensity = (2 * besselj(1, k * r) / (k * r))^2
return intensity
end
# ╔═╡ 9b327272-4ee9-428c-9782-eb9dc1878fac
"""
Takes an image to deconvolve, a wavelength and the diameter of the used aperture and performs the deconvolution using the Point Spread Function of the setup, returning the resulting image
"""
function Deconvolve_PSF(image_to_deconvolve, lambda, aperture_diameter)
width, height = size(image_to_deconvolve)
PSF = [Airy_Disk(norm([i, j]), lambda, aperture_diameter) for i in 1:width, j in 1:height] #Calculus of the Point Spread Function of an optical setup
PSF /= sum(PSF) #Normalization of PSF
deconvolution = imfilter(image_to_deconvolve, PSF)
return deconvolution
end
# ╔═╡ 5885fb2d-442f-4a62-800e-68145bf5ef09
md"""
# Other utilities
"""
# ╔═╡ a61eb8ba-4923-45d5-8b9d-8b122f3d7266
PlutoUI.TableOfContents(title="WideField images analysis", indent=true)
# ╔═╡ Cell order:
# ╟─3afbafe0-1371-11ef-0114-3b191c3f6904
# ╟─40b08f2f-2bfd-4601-9ae5-18b199fce144
# ╠═fadf633b-621f-4f18-bbb5-df18273d2e6c
# ╠═3eac8dee-8709-4ed1-8fc4-ad163f1f5426
# ╟─78f03196-450c-4c51-afc3-5a664b81fef3
# ╠═5b03b13c-a813-4916-b13e-08413b370670
# ╠═12322533-ce10-4382-b527-97ac8c54d6ea
# ╠═7b076d68-ebc9-447e-bde2-815036a3e3d4
# ╟─3bc06e36-0692-4f85-83f8-a1a38c0d9ace
# ╠═6adf724f-73ad-424d-a0cb-2869ce73c3d8
# ╠═904eab41-e58e-4625-8090-4fa39956be19
# ╠═e920f086-b0d4-4aa6-9e69-33bf24d137fa
# ╟─47c48ee0-ca8e-4f58-8fc8-17489d707ff0
# ╠═6ed429a2-41f6-4fa4-8ecb-b39742aa4547
# ╟─db148fe2-143a-49f1-a4bc-10cf7599ea01
# ╠═1fc5a82f-9d59-4fb1-a8f3-fde719bfd20d
# ╠═0bef7c1e-c14d-4455-951b-d30e206dbdfb
# ╟─34a8690e-8ccd-4b4a-8547-b6b73ead33a9
# ╠═a635d61d-4ea2-4c90-9237-8d3668de740b
# ╟─bdc51e2e-21e9-404d-84de-bd776192ecae
# ╠═4896bcfe-fc29-4343-9433-7729dd70d2d0
# ╠═073859fe-d83d-40bb-8cdb-ec1850e8ed1b
# ╠═a9570315-f705-4c41-8309-52d2ad8e0d9f
# ╠═dd338429-8ea0-4404-9af3-74a133ac88d2
# ╟─a189b589-cc79-4736-a345-0a3d28f23cca
# ╠═71f63fe1-bb8c-43ae-bb33-526199edc4ca
# ╟─0063fa47-f32f-4302-bd66-55e6e0a05a03
# ╠═8754abf0-df80-4c2f-9ad7-84350e5161ee
# ╠═4060e35e-61f0-4121-83b8-df90fdca2408
# ╠═f3b34417-8138-4948-a158-e38f169cfae0
# ╟─bbbf0b41-746c-4f01-a1e9-dee2bdbeab48
# ╠═7120159c-df13-4140-9add-f52c43530112
# ╠═e3e900d6-3696-4b5d-b5f2-a74644dd0975
# ╠═ecdc24c0-b4c4-43b8-8f08-3ac97e035686
# ╟─fef0fc51-3c44-4c00-bad9-acbff5df6cf4
# ╟─ca58450a-8f5b-4b48-8dff-f370a7d640f9
# ╠═2f4b2a85-0aba-41ac-8c15-f9fafa26f35b
# ╠═9af3cd4e-a16c-4f09-949d-5ac515e2f327
# ╟─21e6bd2b-ee27-4db4-aa5f-09e95deab2c4
# ╠═0bc1224b-5a4f-4f6e-a668-0dcec4a1fc7e
# ╠═2a5ee74c-e17b-4088-b4d2-0c3f51dcb50b
# ╠═1154c4ca-65d6-411a-9865-45d0cf37a902
# ╠═627ff63b-2e22-4b04-a81d-3816764159c9
# ╠═5211e6b5-b445-4a67-980e-70a2a86cbc31
# ╠═137fbbfa-a807-4137-a3bc-f52899ea6e2f
# ╠═bcdd5938-b934-4aa8-a416-40a70acb8540
# ╠═478008c7-5e3c-486b-a8f8-ddc7daaaeecf
# ╠═14e2baff-6528-4f2f-a355-2b9279650144
# ╠═f9962802-25fb-434e-8eaa-baae842af938
# ╟─25c3886c-d10f-4918-888c-71755f73e193
# ╠═ff932c8a-ad5c-4748-96d8-d9987ea7c6b3
# ╠═0b098090-12ab-4f8b-a9dc-3aaddb4d3b49
# ╠═971825d2-e532-4778-95dc-5092f2f94e19
# ╠═9b327272-4ee9-428c-9782-eb9dc1878fac
# ╟─5885fb2d-442f-4a62-800e-68145bf5ef09
# ╠═a61eb8ba-4923-45d5-8b9d-8b122f3d7266