-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdenoising.jl
4132 lines (3989 loc) · 105 KB
/
denoising.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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.17.2
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
# ╔═╡ f9e001ae-0323-4283-9af1-1a8252b503e7
let
import Pkg
Pkg.activate(".")
Pkg.instantiate()
end
# ╔═╡ 203fb8c8-4358-4908-b616-a691ce329c02
using
Wavelets,
WaveletsExt,
LinearAlgebra,
Plots,
Gadfly,
DataFrames,
PlutoUI,
Statistics
# ╔═╡ 53c257e0-96ba-11eb-3615-8bfed63b2c18
md"# Denoising Experiment"
# ╔═╡ 78225642-d1bb-41ca-9b77-1b9ad1b5d9a0
md"""
## Introduction
Signal denoising is an important step in many signal processing and analysis as it reduce noise in the data while retaining important information. Among the various denoising methods, thresholding is a simple but effective technique for denoising signals and images. In this notebook, we look into some thresholding methods with respect to different types of wavelet transforms.
The two main packages used in this experiment are Wavelets.jl and WaveletsExt.jl.
[Wavelets.jl](https://github.com/JuliaDSP/Wavelets.jl) is a very useful package for wavelet analysis in Julia, as it contains important preliminary tools such as wavelet constructors, wavelet transform, and thresholding functions.
[WaveletsExt.jl](https://github.com/UCD4IDS/WaveletsExt.jl) on the other hand, is an extension package to Wavelets.jl with added support for the stationary wavelet transforms (SWT), the autocorrelation wavelet transform (ACWT) and group-based best basis algorithms such as the joint best basis (JBB) and least-statistically dependent basis (LSDB).
In this experiment, we will compare and contrast the signal denoising strengths and weaknesses of different wavelet transform and threshold selection methods. Specifically, given a wavelet, a group of signals of length $2^L$ and a threshold method (eg. Hard thresholding), we will compare the denoising ability between:
* type of wavelet transform:
* regular discrete wavelet transforms.
* regular wavelet packet decomposition up to $L/2$ levels.
* regular wavelet packet decomposition up to $L$ levels.
* regular wavelet packet best basis transforms.
* regular wavelet packet joint best basis transforms.
* regular wavelet packet least-statistically dependent basis transforms.
* autocorrelation discrete wavelet transforms.
* autocorrelation wavelet packet decomposition up to $L/2$ levels.
* autocorrelation wavelet packet decomposition up to $L$ levels.
* autocorrelation wavelet packet best basis transforms.
* autocorrelation wavelet packet joint best basis transforms.
* autocorrelation wavelet packet least-statistically dependent basis transforms.
* stationary discrete wavelet transforms.
* stationary wavelet packet decomposition up to $L/2$ levels.
* stationary wavelet packet decomposition up to $L$ levels.
* stationary wavelet packet best basis transforms.
* stationary wavelet packet joint best basis transforms.
* stationary wavelet packet least-statistically dependent basis transforms.
* type of threshold selection algorithm:
* VisuShrink developed by D. Donoho and I. Johnstone.
* RelErrorShrink used in N. Saito and J. Irion in their paper ["Efficient Approximation and Denoising of Graph Signals Using the Multiscale Best Basis Dictionaries"](https://escholarship.org/content/qt0bv9t4c8/qt0bv9t4c8_noSplash_66d3d84d7c4f3146a80f5611e0214b1b.pdf).
* SureShrink developed by D. Donoho and I. Johnstone.
* selection of the best threshold values:
* using individual best threshold values selected from the threshold selection algorithm.
* using the average of the best threshold values selected from the threshold selection algorithm.
* using the median of the best threshold values selected from the threshold selection algorithm.
"""
# ╔═╡ ce4bf94e-edef-40c2-8ac5-b741e47a1759
md"""
## Activate environment
This is used for activating the project environment and is specifically catered for users who cloned the notebook repository.
**Do not change anything in the following block of code.**
"""
# ╔═╡ 85c26ead-f043-42c8-8245-58c8d03a963d
md"""
## Import libraries
**Do not change anything in the following block of code.**
"""
# ╔═╡ 46e30602-a850-4175-b4bf-b4ef4b5359aa
md"""
## A Brief Demonstration
The purpose of this section is for the us to gain an general understanding of signal denoising via wavelets. We can choose from 6 standard test signals and adjust the magnitude of random noise we want to add. Finally, we can choose between two types of thresholding (hard or soft) and adjust our threshold value to see how it effects the resulting denoised signal.
"""
# ╔═╡ b0a28618-7cda-4c05-83d2-b54bbca3f9b5
md"""
**Select** a test function. These signals are obtained from D. Donoho and I. Johnstone in ["Adapting to Unknown Smoothness via Wavelet Shrinkage"](http://statweb.stanford.edu/~imj/WEBLIST/1995/ausws.pdf) Preprint Stanford, January 93, p 27-28.
$(@bind signal_name_test Select(
["blocks", "bumps", "heavisine", "doppler", "quadchirp", "mishmash"],
default = "doppler"
))
"""
# ╔═╡ bb147649-36bf-4a82-95bf-2d5080873028
md"""
**Select** which type of wavelet to use: $(@bind wavelet_type_test Select(
["WT.haar",
"WT.db1", "WT.db2", "WT.db3", "WT.db4", "WT.db5",
"WT.db6", "WT.db7", "WT.db8", "WT.db9", "WT.db10",
"WT.coif2", "WT.coif4", "WT.coif6", "WT.coif8",
"WT.sym4", "WT.sym5", "WT.sym6", "WT.sym7", "WT.sym8", "WT.sym9", "WT.sym10",
"WT.batt2", "WT.batt4", "WT.batt6"],
default = "WT.haar"
))
"""
# ╔═╡ ff1bfee3-2f30-4d15-9f3a-e3f422e67d72
md"""
**Select** the value $L$ for signal of length $2^L$
$(@bind max_dec_level_test Slider(6:1:10, default=7, show_value=true))
"""
# ╔═╡ 458a5a1e-c453-4199-befe-2bf4db6825ae
md"""
**Adjust** the magnitude of Gaussian noise
$(@bind noise_size_test Slider(0:0.01:1, default=0.3, show_value=true))
"""
# ╔═╡ a184ae65-7947-4ffb-b751-8b6e97a8608b
function addnoise(x::AbstractArray{<:Number,1}, s::Real=0.1)
ϵ = randn(length(x))
ϵ = ϵ/norm(ϵ)
y = x + ϵ * s * norm(x)
return y
end;
# ╔═╡ faa0a4ea-7849-408a-ac0f-c5cca8761aee
md"""
The plots above shows the decomposition levels, with finest at the top and coursest at the bottom, of the noisy signal via 1) autocorrelation discrete wavelet transform (ACWT), 2) stationary discrete wavelet transform (SWT), and 3) the regular discrete wavelet transform (DWT).
From them, we can see that ACWT and SWT are better at retaining the shape of the original signal compared to the DWT.
**Note:** As the DWT is non-redundant (ie. downsampling takes place with a factor of 2 at every level) we cannot conclude that DWT is inferior simply based on a visual comparison with ACWT and SWT. The wavelet coefficients for the DWT were padded and extended such that they obtain the length of the original signal. This is done strictly for illustration purposes only.
"""
# ╔═╡ f313da22-8460-462f-8c0d-2055aef00d5e
md"""
In order to remove the noise from the signal, we take the following two steps:
1. Threshold the wavelet coefficients. We can use either hard thresholding or soft thresholding.
2. Reconstruct the signal from the thresholded coefficients.
"""
# ╔═╡ 9eae2f5c-1f47-43d8-a7ec-0767e50e6a9b
md"""
**Select** threshold type
$(@bind th_method_test Radio(["Hard", "Soft"], default = "Hard"))
"""
# ╔═╡ 11e63c9a-6124-4122-9a86-ceed926d25d2
md"## Experimental Data Setup"
# ╔═╡ d881753b-0432-451b-8de0-38a0b4b4382a
md"**Autorun**: $(@bind autorun CheckBox())
**Note:** Disable before updating parameters! "
# ╔═╡ 8055194b-2e46-4d18-81c0-0c52bc3eb233
md"""
**Select** a test function $(@bind signal_name Select(
[
"blocks" => "Blocks",
"bumps" => "Bumps",
"heavisine" => "Heavisine",
"doppler" => "Doppler",
"quadchirp" => "Quadchirp",
"mishmash" => "Mishmash"
],
default = "blocks"
))
"""
# ╔═╡ f6277c19-1989-449e-96ba-6f81db68c76b
md"""
**Select** the value $L$ for signal of length $2^L$
*Warning: The computation starts to take extremely long when setting $L \geq 9$.*
$(@bind max_dec_level Slider(6:1:10, default=7, show_value=true))
"""
# ╔═╡ 56ee2c61-d83c-4d76-890a-a9bd0d65cee5
md"**Adjust** the slider to add Gaussian noise to the test signal"
# ╔═╡ c50ac92e-3684-4d0a-a80d-4ee9d74ec992
@bind noise_size Slider(0:0.01:1, default=0.3, show_value=true)
# ╔═╡ e0a96592-5e77-4c29-9744-31369eea8147
md"""
**Select** which type of wavelet to use: $(@bind wavelet_type Select(
["WT.haar",
"WT.db1", "WT.db2", "WT.db3", "WT.db4", "WT.db5",
"WT.db6", "WT.db7", "WT.db8", "WT.db9", "WT.db10",
"WT.coif2", "WT.coif4", "WT.coif6", "WT.coif8",
"WT.sym4", "WT.sym5", "WT.sym6", "WT.sym7", "WT.sym8", "WT.sym9", "WT.sym10",
"WT.batt2", "WT.batt4", "WT.batt6"],
default = "WT.haar"
))
"""
# ╔═╡ 49db1715-8d7d-4815-9972-8f3fc6895754
begin
wt_test = wavelet(eval(Meta.parse(wavelet_type)))
x_test = generatesignals(Symbol(signal_name_test), max_dec_level_test)
p1_test = Plots.plot(x_test,
ylim = (minimum(x_test)-1,maximum(x_test)+1),
lc = "black",
lw = 2,
label = "Original signal",
xlabel = "Original vs Noisy"
)
x_noisy_test = addnoise(x_test, noise_size_test)
Plots.plot!(x_noisy_test, lw =1.5, label = "Noisy signal");
y_test = acdwt(x_noisy_test, wt_test, max_dec_level_test÷2);
p2_test = WaveletsExt.wiggle(y_test, Overlap=false)
Plots.plot!(p2_test, xlabel = "Autocorrelation Transform of Noisy Signal")
z_test = sdwt(x_noisy_test, wt_test, max_dec_level_test÷2);
p3_test = WaveletsExt.wiggle(z_test, Overlap=false)
Plots.plot!(p3_test, xlabel = "Stationary Transform of Noisy Signal")
function extend_signal(x::AbstractVector{T}, l::Int) where T
n = length(x) # signal length
L = maxtransformlevels(x) # max transform levels of x
y = Array{T,2}(undef, (n,l+1))
lv = l # level of bottom left node
nₙ = nodelength(n,l) # length of bottom left node
y[:,1] = repeat(x[1:nₙ], inner=1<<lv)
st = nₙ+1
for i in 2:(l+1)
rng = st:(st+nₙ-1)
y[:,i] = repeat(x[rng], inner=1<<lv)
lv -= 1
st += nₙ
nₙ *= 2
end
return y
end
w_test = dwt(x_noisy_test, wt_test, max_dec_level_test÷2);
we_test = extend_signal(w_test, max_dec_level_test÷2)
p4_test = WaveletsExt.wiggle(we_test, Overlap=false)
Plots.plot!(p4_test, xlabel = "Regular Transform of Noisy Signal")
Plots.plot(p1_test, p2_test, p3_test, p4_test, layout = (4,1), size=(600, 800))
end
# ╔═╡ dbed8579-afa4-4a4d-b0bb-bd34877fa272
md"""
The slider below allows us to adjust the threshold value to observe the effect on the reconstructed/denoised signal.
**Select** a threshold value
$(@bind th_test Slider(0:0.01:maximum(y_test), default = 0, show_value = true))
"""
# ╔═╡ e49e76e6-7018-4f49-a189-d2fae7df956d
begin
ŷ_test = copy(y_test)
ẑ_test = copy(z_test)
ŵ_test = copy(w_test)
if th_method_test == "Hard"
threshold!(ŷ_test, HardTH(), th_test);
threshold!(ẑ_test, HardTH(), th_test);
threshold!(ŵ_test, HardTH(), th_test);
else
threshold!(ŷ_test, SoftTH(), th_test);
threshold!(ẑ_test, SoftTH(), th_test);
threshold!(ŵ_test, SoftTH(), th_test);
end
end;
# ╔═╡ 9b4ef541-9a36-4bc0-8654-10ab0a4e63b3
begin
# reconstruction
r1_test = iacdwt(ŷ_test)
r2_test = isdwt(ẑ_test, wt_test)
r3_test = idwt(ŵ_test, wt_test, max_dec_level_test÷2)
# plot original vs ACWT-denoised
d1_test = Plots.plot(x_test, label = "original", lc = "black", lw=2)
Plots.plot!(d1_test, r1_test, label = "ACWT denoised", lc="green", lw=1.5)
Plots.plot!(d1_test, x_noisy_test, label = "noisy", lc = "gray", la = 0.8)
# plot original vs SDWT-denoised
d2_test = Plots.plot(x_test, label = "original", lc = "black", lw=2)
Plots.plot!(d2_test, r2_test, label = "SWT denoised", lc="green", lw=1.5)
Plots.plot!(d2_test, x_noisy_test, label = "noisy", lc = "gray", la = 0.8)
# plot original vs DWT-denoised
d3_test = Plots.plot(x_test, label = "original", lc = "black", lw=2)
Plots.plot!(d3_test, r3_test, label = "DWT denoised", lc="green", lw=1.5)
Plots.plot!(d3_test, x_noisy_test, label = "noisy", lc = "gray", la = 0.8)
# display all plots
Plots.plot(d1_test, d2_test, d3_test, layout = (3,1), size=(600, 600))
end
# ╔═╡ 4669be94-6c4c-42e2-b9d9-2dc98f1bdaea
md"""
Here are some metrics to determine how well our signal thresholding fared:
* Relative 2-norm between original signal and denoised signal (smaller value indicates better result)
| Signal | Relative 2-norm |
| :---: | :---: |
| noisy | $(round(relativenorm(x_noisy_test, x_test), digits = 4)) |
| ACWT denoised | $(round(relativenorm(r1_test, x_test), digits = 4)) |
| SWT denoised | $(round(relativenorm(r2_test, x_test), digits = 4)) |
| DWT denoised | $(round(relativenorm(r3_test, x_test), digits = 4)) |
* PSNR between original signal and denoised signal (larger value indicates better result)
| Signal | PSNR |
| :---: | :---: |
| noisy | $(round(psnr(x_noisy_test, x_test), digits = 4)) |
| ACWT denoised | $(round(psnr(r1_test, x_test), digits = 4)) |
| SWT denoised | $(round(psnr(r2_test, x_test), digits = 4)) |
| DWT denoised | $(round(psnr(r3_test, x_test), digits = 4)) |
* SSIM between original signal and denoised signal (larger value indicates better result)
| Signal | SSIM |
| :---: | :---: |
| noisy | $(round(ssim(x_noisy_test, x_test), digits = 4)) |
| ACWT denoised | $(round(ssim(r1_test, x_test), digits = 4)) |
| SWT denoised | $(round(ssim(r2_test, x_test), digits = 4)) |
| DWT denoised | $(round(ssim(r3_test, x_test), digits = 4)) |
"""
# ╔═╡ c178527f-96a4-4ac7-bb0c-38b73b38c45b
md"""
**Select** which type of thresholding to use: $(@bind threshold_method Select(
["HardTH()" => "Hard",
"SoftTH()" => "Soft",
"SteinTH()" => "Stein"],
default = "HardTH()"
))
"""
# ╔═╡ ef3e7b66-fba0-467a-8a73-c9bf31fadbe3
md"""
**Key in** the sample size: $(@bind ss TextField((5,1), default="10"))
"""
# ╔═╡ cd9e259e-8bb3-497b-ac7f-f89a003c8032
begin
x = generatesignals(Symbol(signal_name), max_dec_level)
p3 = Plots.plot(
x,
ylim = (minimum(x)-1,maximum(x)+1),
lc = "black",
lw = 2,
label = "Original signal"
)
x_noisy = addnoise(x, noise_size)
Plots.plot!(x_noisy, lw = 1.5, label = "Noisy signal");
end
# ╔═╡ 82e713f8-c870-43d2-a849-e3b401b00459
begin
if autorun
samplesize = parse(Int64, ss)
X₀ = duplicatesignals(x, samplesize, 2)
X = hcat([addnoise(X₀[:,i], noise_size) for i in axes(X₀,2)]...)
end
end;
# ╔═╡ 6b02c425-39b9-467f-9406-3e9096873af4
begin
if autorun
wt = wavelet(eval(Meta.parse(wavelet_type)))
th = eval(Meta.parse(threshold_method))
vs_dnt = VisuShrink(256, th)
res_dnt = RelErrorShrink(th)
# define variables to store results
Y = Dict{String, AbstractArray}() # Decompositions
X̂ = Dict{String, AbstractArray}()
T = Dict{String, AbstractArray}() # Trees
σ₁= Dict{String, AbstractArray}() # Noise estimates for VisuShrink
σ₂= Dict{String, AbstractArray}() # Noise estimates for RelErrorShrink
time = Dict{String, AbstractFloat}()
mean_psnr = Dict{String, AbstractFloat}()
mean_ssim = Dict{String, AbstractFloat}()
results = DataFrame(
transform = ["None"],
threshold = ["None"],
shrinking = ["None"],
selection = ["None"],
time = 0.0,
PSNR = mean([psnr(X[:,i], X₀[:,i]) for i in axes(X,2)]),
SSIM = mean([ssim(X[:,i], X₀[:,i]) for i in axes(X,2)])
)
end
end
# ╔═╡ 95081e88-a623-4e91-99c1-8b254b366dac
md"Once you are satisfied with the selected parameters, enabling the **autorun** option above will prompt the experiment to run.
For the following sections, the code is not displayed in order to keep this notebook short. To display the code hover your pointer over the blank areas and click on the eye symbol that will appear to the left."
# ╔═╡ 126c41e7-dd65-46c6-8c5b-2439f5624fd5
md"# Non-Redundant Transforms"
# ╔═╡ 17bdc97a-4a0b-4931-a5c6-866f0c814601
md"#### Discrete Wavelet Transform"
# ╔═╡ 01e43234-2194-451d-9010-176aa4799fdb
begin
if autorun
# Visushrink
Y["DWT"] = dwtall(X, wt)
σ₁["DWT"] = [noisest(Y["DWT"][:,i], false) for i in axes(X,2)]
σ₂["DWT"] = [relerrorthreshold(Y["DWT"][:,i], false) for i in axes(X,2)]
## bestTH = individual
X̂["DWT_vs_ind"], time["DWT_vs_ind"] = @timed denoiseall(
Y["DWT"],
:dwt,
wt,
L=max_dec_level,
estnoise=σ₁["DWT"],
dnt=vs_dnt,
bestTH=nothing
)
mean_psnr["DWT_vs_ind"] = mean(
[psnr(X̂["DWT_vs_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["DWT_vs_ind"] = mean(
[ssim(X̂["DWT_vs_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"DWT",
threshold_method,
"VisuShrink",
"Individual",
time["DWT_vs_ind"],
mean_psnr["DWT_vs_ind"],
mean_ssim["DWT_vs_ind"]
]
)
## bestTH = average
X̂["DWT_vs_avg"], time["DWT_vs_avg"] = @timed denoiseall(
Y["DWT"],
:dwt,
wt,
L=max_dec_level,
estnoise=σ₁["DWT"],
dnt=vs_dnt,
bestTH=mean
)
mean_psnr["DWT_vs_avg"] = mean(
[psnr(X̂["DWT_vs_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["DWT_vs_avg"] = mean(
[ssim(X̂["DWT_vs_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"DWT",
threshold_method,
"VisuShrink",
"Average",
time["DWT_vs_avg"],
mean_psnr["DWT_vs_avg"],
mean_ssim["DWT_vs_avg"]
]
)
## bestTH = median
X̂["DWT_vs_med"], time["DWT_vs_med"] = @timed denoiseall(
Y["DWT"],
:dwt,
wt,
L=max_dec_level,
estnoise=σ₁["DWT"],
dnt=vs_dnt,
bestTH=median
)
mean_psnr["DWT_vs_med"] = mean(
[psnr(X̂["DWT_vs_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["DWT_vs_med"] = mean(
[ssim(X̂["DWT_vs_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"DWT",
threshold_method,
"VisuShrink",
"Median",
time["DWT_vs_med"],
mean_psnr["DWT_vs_med"],
mean_ssim["DWT_vs_med"]
]
)
# RelErrorShrink
## bestTH = individual
X̂["DWT_res_ind"], time["DWT_res_ind"] = @timed denoiseall(
Y["DWT"],
:dwt,
wt,
L=max_dec_level,
estnoise=σ₂["DWT"],
dnt=res_dnt,
bestTH=nothing
)
mean_psnr["DWT_res_ind"] = mean(
[psnr(X̂["DWT_res_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["DWT_res_ind"] = mean(
[ssim(X̂["DWT_res_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"DWT",
threshold_method,
"RelErrorShrink",
"Individual",
time["DWT_res_ind"],
mean_psnr["DWT_res_ind"],
mean_ssim["DWT_res_ind"]
]
)
## bestTH = average
X̂["DWT_res_avg"], time["DWT_res_avg"] = @timed denoiseall(
Y["DWT"],
:dwt,
wt,
L=max_dec_level,
estnoise=σ₂["DWT"],
dnt=res_dnt,
bestTH=mean
)
mean_psnr["DWT_res_avg"] = mean(
[psnr(X̂["DWT_res_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["DWT_res_avg"] = mean(
[ssim(X̂["DWT_res_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"DWT",
threshold_method,
"RelErrorShrink",
"Average",
time["DWT_res_avg"],
mean_psnr["DWT_res_avg"],
mean_ssim["DWT_res_avg"]
]
)
## bestTH = median
X̂["DWT_res_med"], time["DWT_res_med"] = @timed denoiseall(
Y["DWT"],
:dwt,
wt,
L=max_dec_level,
estnoise=σ₂["DWT"],
dnt=res_dnt,
bestTH=median
)
mean_psnr["DWT_res_med"] = mean(
[psnr(X̂["DWT_res_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["DWT_res_med"] = mean(
[ssim(X̂["DWT_res_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"DWT",
threshold_method,
"RelErrorShrink",
"Median",
time["DWT_res_med"],
mean_psnr["DWT_res_med"],
mean_ssim["DWT_res_med"]
]
)
end
end;
# ╔═╡ ae8059bd-5b5b-4ff2-a6f0-5ce672bdd54d
md"#### Wavelet Packet Transform - Level $(max_dec_level÷2)"
# ╔═╡ cf55c5cb-ead6-40b6-896a-8f7e01613a46
begin
if autorun
# Visushrink
Y["WPT$(max_dec_level÷2)"] = wptall(X, wt, max_dec_level÷2)
T["WPT$(max_dec_level÷2)"] = maketree(
1<<max_dec_level, max_dec_level÷2, :full
)
σ₁["WPT$(max_dec_level÷2)"] = [
noisest(
Y["WPT$(max_dec_level÷2)"][:,i], false, T["WPT$(max_dec_level÷2)"]
) for i in axes(X,2)
]
σ₂["WPT$(max_dec_level÷2)"] = [
relerrorthreshold(
Y["WPT$(max_dec_level÷2)"][:,i], false, T["WPT$(max_dec_level÷2)"]
) for i in axes(X,2)
]
## bestTH = individual
X̂["WPT$(max_dec_level÷2)_vs_ind"], time["WPT$(max_dec_level÷2)_vs_ind"] =
@timed denoiseall(
Y["WPT$(max_dec_level÷2)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level÷2)"],
estnoise=σ₁["WPT$(max_dec_level÷2)"],
dnt=vs_dnt,
bestTH=nothing
)
mean_psnr["WPT$(max_dec_level÷2)_vs_ind"] = mean(
[psnr(X̂["WPT$(max_dec_level÷2)_vs_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level÷2)_vs_ind"] = mean(
[ssim(X̂["WPT$(max_dec_level÷2)_vs_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level÷2)",
threshold_method,
"VisuShrink",
"Individual",
time["WPT$(max_dec_level÷2)_vs_ind"],
mean_psnr["WPT$(max_dec_level÷2)_vs_ind"],
mean_ssim["WPT$(max_dec_level÷2)_vs_ind"]
]
)
## bestTH = average
X̂["WPT$(max_dec_level÷2)_vs_avg"], time["WPT$(max_dec_level÷2)_vs_avg"] =
@timed denoiseall(
Y["WPT$(max_dec_level÷2)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level÷2)"],
estnoise=σ₁["WPT$(max_dec_level÷2)"],
dnt=vs_dnt,
bestTH=mean
)
mean_psnr["WPT$(max_dec_level÷2)_vs_avg"] = mean(
[psnr(X̂["WPT$(max_dec_level÷2)_vs_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level÷2)_vs_avg"] = mean(
[ssim(X̂["WPT$(max_dec_level÷2)_vs_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level÷2)",
threshold_method,
"VisuShrink",
"Average",
time["WPT$(max_dec_level÷2)_vs_avg"],
mean_psnr["WPT$(max_dec_level÷2)_vs_avg"],
mean_ssim["WPT$(max_dec_level÷2)_vs_avg"]
]
)
## bestTH = median
X̂["WPT$(max_dec_level÷2)_vs_med"], time["WPT$(max_dec_level÷2)_vs_med"] =
@timed denoiseall(
Y["WPT$(max_dec_level÷2)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level÷2)"],
estnoise=σ₁["WPT$(max_dec_level÷2)"],
dnt=vs_dnt,
bestTH=median
)
mean_psnr["WPT$(max_dec_level÷2)_vs_med"] = mean(
[psnr(X̂["WPT$(max_dec_level÷2)_vs_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level÷2)_vs_med"] = mean(
[ssim(X̂["WPT$(max_dec_level÷2)_vs_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level÷2)",
threshold_method,
"VisuShrink",
"Median",
time["WPT$(max_dec_level÷2)_vs_med"],
mean_psnr["WPT$(max_dec_level÷2)_vs_med"],
mean_ssim["WPT$(max_dec_level÷2)_vs_med"]
]
)
# RelErrorShrink
## bestTH = individual
X̂["WPT$(max_dec_level÷2)_res_ind"], time["WPT$(max_dec_level÷2)_res_ind"] =
@timed denoiseall(
Y["WPT$(max_dec_level÷2)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level÷2)"],
estnoise=σ₂["WPT$(max_dec_level÷2)"],
dnt=res_dnt,
bestTH=nothing
)
mean_psnr["WPT$(max_dec_level÷2)_res_ind"] = mean(
[psnr(X̂["WPT$(max_dec_level÷2)_res_ind"][:,i],X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level÷2)_res_ind"] = mean(
[ssim(X̂["WPT$(max_dec_level÷2)_res_ind"][:,i],X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level÷2)",
threshold_method,
"RelErrorShrink",
"Individual",
time["WPT$(max_dec_level÷2)_res_ind"],
mean_psnr["WPT$(max_dec_level÷2)_res_ind"],
mean_ssim["WPT$(max_dec_level÷2)_res_ind"]
]
)
## bestTH = average
X̂["WPT$(max_dec_level÷2)_res_avg"], time["WPT$(max_dec_level÷2)_res_avg"] =
@timed denoiseall(
Y["WPT$(max_dec_level÷2)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level÷2)"],
estnoise=σ₂["WPT$(max_dec_level÷2)"],
dnt=res_dnt,
bestTH=mean
)
mean_psnr["WPT$(max_dec_level÷2)_res_avg"] = mean(
[psnr(X̂["WPT$(max_dec_level÷2)_res_avg"][:,i],X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level÷2)_res_avg"] = mean(
[ssim(X̂["WPT$(max_dec_level÷2)_res_avg"][:,i],X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level÷2)",
threshold_method,
"RelErrorShrink",
"Average",
time["WPT$(max_dec_level÷2)_res_avg"],
mean_psnr["WPT$(max_dec_level÷2)_res_avg"],
mean_ssim["WPT$(max_dec_level÷2)_res_avg"]
]
)
## bestTH = median
X̂["WPT$(max_dec_level÷2)_res_med"], time["WPT$(max_dec_level÷2)_res_med"] =
@timed denoiseall(
Y["WPT$(max_dec_level÷2)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level÷2)"],
estnoise=σ₂["WPT$(max_dec_level÷2)"],
dnt=res_dnt,
bestTH=median
)
mean_psnr["WPT$(max_dec_level÷2)_res_med"] = mean(
[psnr(X̂["WPT$(max_dec_level÷2)_res_med"][:,i],X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level÷2)_res_med"] = mean(
[ssim(X̂["WPT$(max_dec_level÷2)_res_med"][:,i],X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level÷2)",
threshold_method,
"RelErrorShrink",
"Median",
time["WPT$(max_dec_level÷2)_res_med"],
mean_psnr["WPT$(max_dec_level÷2)_res_med"],
mean_ssim["WPT$(max_dec_level÷2)_res_med"]
]
)
end
end;
# ╔═╡ c95ebbed-3d9a-4be2-943b-08c86923ad89
md"#### Wavelet Packet Transform - Level $(max_dec_level)"
# ╔═╡ 61d745d8-5c74-479b-9698-cd50bb68b3c7
begin
if autorun
# Visushrink
Y["WPT$(max_dec_level)"] = wptall(X, wt, max_dec_level)
T["WPT$(max_dec_level)"] = maketree(1<<max_dec_level, max_dec_level, :full)
σ₁["WPT$(max_dec_level)"] = [
noisest(
Y["WPT$(max_dec_level)"][:,i], false, T["WPT$(max_dec_level)"]
) for i in axes(X,2)
]
σ₂["WPT$(max_dec_level)"] = [
relerrorthreshold(
Y["WPT$(max_dec_level)"][:,i], false, T["WPT$(max_dec_level)"]
) for i in axes(X,2)
]
## bestTH = individual
X̂["WPT$(max_dec_level)_vs_ind"], time["WPT$(max_dec_level)_vs_ind"] =
@timed denoiseall(
Y["WPT$(max_dec_level)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level)"],
estnoise=σ₁["WPT$(max_dec_level)"],
dnt=vs_dnt,
bestTH=nothing
)
mean_psnr["WPT$(max_dec_level)_vs_ind"] = mean(
[psnr(X̂["WPT$(max_dec_level)_vs_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level)_vs_ind"] = mean(
[ssim(X̂["WPT$(max_dec_level)_vs_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level)",
threshold_method,
"VisuShrink",
"Individual",
time["WPT$(max_dec_level)_vs_ind"],
mean_psnr["WPT$(max_dec_level)_vs_ind"],
mean_ssim["WPT$(max_dec_level)_vs_ind"]
]
)
## bestTH = average
X̂["WPT$(max_dec_level)_vs_avg"], time["WPT$(max_dec_level)_vs_avg"] =
@timed denoiseall(
Y["WPT$(max_dec_level)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level)"],
estnoise=σ₁["WPT$(max_dec_level)"],
dnt=vs_dnt,
bestTH=mean
)
mean_psnr["WPT$(max_dec_level)_vs_avg"] = mean(
[psnr(X̂["WPT$(max_dec_level)_vs_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level)_vs_avg"] = mean(
[ssim(X̂["WPT$(max_dec_level)_vs_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level)",
threshold_method,
"VisuShrink",
"Average",
time["WPT$(max_dec_level)_vs_avg"],
mean_psnr["WPT$(max_dec_level)_vs_avg"],
mean_ssim["WPT$(max_dec_level)_vs_avg"]
]
)
## bestTH = median
X̂["WPT$(max_dec_level)_vs_med"], time["WPT$(max_dec_level)_vs_med"] =
@timed denoiseall(
Y["WPT$(max_dec_level)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level)"],
estnoise=σ₁["WPT$(max_dec_level)"],
dnt=vs_dnt,
bestTH=median
)
mean_psnr["WPT$(max_dec_level)_vs_med"] = mean(
[psnr(X̂["WPT$(max_dec_level)_vs_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level)_vs_med"] = mean(
[ssim(X̂["WPT$(max_dec_level)_vs_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level)",
threshold_method,
"VisuShrink",
"Median",
time["WPT$(max_dec_level)_vs_med"],
mean_psnr["WPT$(max_dec_level)_vs_med"],
mean_ssim["WPT$(max_dec_level)_vs_med"]
]
)
# RelErrorShrink
## bestTH = individual
X̂["WPT$(max_dec_level)_res_ind"], time["WPT$(max_dec_level)_res_ind"] =
@timed denoiseall(
Y["WPT$(max_dec_level)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level)"],
estnoise=σ₂["WPT$(max_dec_level)"],
dnt=res_dnt,
bestTH=nothing
)
mean_psnr["WPT$(max_dec_level)_res_ind"] = mean(
[psnr(X̂["WPT$(max_dec_level)_res_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level)_res_ind"] = mean(
[ssim(X̂["WPT$(max_dec_level)_res_ind"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level)",
threshold_method,
"RelErrorShrink",
"Individual",
time["WPT$(max_dec_level)_res_ind"],
mean_psnr["WPT$(max_dec_level)_res_ind"],
mean_ssim["WPT$(max_dec_level)_res_ind"]
]
)
## bestTH = average
X̂["WPT$(max_dec_level)_res_avg"], time["WPT$(max_dec_level)_res_avg"] =
@timed denoiseall(
Y["WPT$(max_dec_level)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level)"],
estnoise=σ₂["WPT$(max_dec_level)"],
dnt=res_dnt,
bestTH=mean
)
mean_psnr["WPT$(max_dec_level)_res_avg"] = mean(
[psnr(X̂["WPT$(max_dec_level)_res_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level)_res_avg"] = mean(
[ssim(X̂["WPT$(max_dec_level)_res_avg"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level)",
threshold_method,
"RelErrorShrink",
"Average",
time["WPT$(max_dec_level)_res_avg"],
mean_psnr["WPT$(max_dec_level)_res_avg"],
mean_ssim["WPT$(max_dec_level)_res_avg"]
]
)
## bestTH = median
X̂["WPT$(max_dec_level)_res_med"], time["WPT$(max_dec_level)_res_med"] = @timed denoiseall(
Y["WPT$(max_dec_level)"],
:wpt,
wt,
tree=T["WPT$(max_dec_level)"],
estnoise=σ₂["WPT$(max_dec_level)"],
dnt=res_dnt,
bestTH=median
)
mean_psnr["WPT$(max_dec_level)_res_med"] = mean(
[psnr(X̂["WPT$(max_dec_level)_res_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
mean_ssim["WPT$(max_dec_level)_res_med"] = mean(
[ssim(X̂["WPT$(max_dec_level)_res_med"][:,i], X₀[:,i]) for i in axes(X,2)]
)
push!(
results,
[
"WPT-L$(max_dec_level)",
threshold_method,
"RelErrorShrink",
"Median",
time["WPT$(max_dec_level)_res_med"],
mean_psnr["WPT$(max_dec_level)_res_med"],
mean_ssim["WPT$(max_dec_level)_res_med"]
]
)
end