-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_overhead_tile.ps1
82 lines (67 loc) · 1.65 KB
/
extract_overhead_tile.ps1
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
param(
[string]$overhead,
[string]$ground,
[string]$out,
[string]$fuzz="2%",
[string]$closing_kernel="Disk:1",
[string]$opening_kernel="Disk:1",
[int]$closing_iterations=1,
[int]$opening_iterations=1,
[int]$close_area_threshold=20,
[int]$open_area_threshold=20,
[switch]$stop_after_comparing,
[switch]$stop_after_closing,
[switch]$stop_after_opening,
[switch]$skip_to_masking,
[switch]$skip_to_closing,
[switch]$skip_to_opening
)
function EOT-Compare {
echo Comparing
magick.exe compare -fuzz $fuzz $overhead $ground -compose src -highlight-color red -lowlight-color white $out
}
function EOT-Close {
for($i=0; $i -lt $closing_iterations; $i++){
echo Closing
magick.exe $out -morphology Close $closing_kernel $out
}
}
function EOT-Connect {
param(
[int]$area_threshold
)
echo Connecting
magick.exe convert $out -define connected-components:area-threshold=$area_threshold -define connected-components:mean-color=true -connected-components 2 $out
}
function EOT-Open {
for($i=0; $i -lt $opening_iterations; $i++){
echo Opening
magick.exe $out -morphology Open $opening_kernel $out
}
}
function EOT-Mask {
echo Masking
magick.exe $out -transparent white $out # making the non-red part of the image transparent
magick.exe composite $overhead -compose src-in $out $out # masking the original image
}
if(!$skip_to_masking){
if(!$skip_to_opening){
if(!$skip_to_closing){
EOT-Compare
if ($stop_after_comparing){
Exit
}
}
EOT-Close
EOT-Connect $close_area_threshold
if ($stop_after_closing){
Exit
}
}
EOT-Open
EOT-Connect $open_area_threshold
if ($stop_after_opening){
Exit
}
}
EOT-Mask