-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtesting.cc
193 lines (170 loc) · 6.08 KB
/
testing.cc
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
#include <vw/Core.h>
#include <vw/Image.h>
#include <vw/FileIO.h>
#include <vw/Stereo/CorrelationView.h>
#include <vw/Stereo/DisparityMap.h>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <PatchMatch2NCC.h>
#include <SurfaceFitView.h>
#include <IterativeMappingStereo.h>
using namespace vw;
void blur_disparity(ImageView<PixelMask<Vector2f> >& sf_disparity,
BBox2i const& disparity_bounds) {
select_channel(sf_disparity,0) =
clamp(gaussian_filter(select_channel(sf_disparity,0),5),
disparity_bounds.min()[0],
disparity_bounds.max()[0]);
select_channel(sf_disparity,1) =
clamp(gaussian_filter(select_channel(sf_disparity,1),5),
disparity_bounds.min()[1],
disparity_bounds.max()[1]);
}
void copy_valid(ImageView<PixelMask<Vector2f> >& destination,
ImageView<PixelMask<Vector2f> >& source) {
for (int j = 0; j < destination.rows(); j++ ) {
for (int i = 0; i < destination.cols(); i++ ) {
if (is_valid(source(i,j))) {
destination(i,j) = source(i,j);
}
}
}
}
int main(int argc, char **argv) {
DiskImageView<float>
left_disk_image("arctic/asp_al-L.crop.32.tif"),
right_disk_image("arctic/asp_al-R.crop.32.tif");
// This is the search range for the final full scale image
BBox2i search_region(Vector2i(-566, -224),
Vector2i(818, 110));
BBox2i per_level_search(-4, -4, 8, 8);
ImageView<PixelMask<Vector2i> > pm_disparity;
{
vw::Timer corr_timer("Correlation Time");
pm_disparity =
block_rasterize
(stereo::patch_match_ncc((left_disk_image),
(right_disk_image),
search_region/32,
Vector2i(15, 15), 2 , 16),
Vector2i(256, 256));
write_image("patchmatch32-D.tif", pm_disparity);
}
ImageView<PixelMask<Vector2f> > sf_disparity;
{
vw::Timer surface_timer("Surface Fitting time");
sf_disparity = block_rasterize(stereo::surface_fit(pm_disparity),
Vector2i(64, 64));
write_image("surface32-D.tif", sf_disparity);
}
{
vw::Timer timer("Bluring");
blur_disparity(sf_disparity, search_region/32);
write_image("surface-blur32-D.tif", sf_disparity);
}
for (int i = 4; i > 0; i--) {
std::cout << "Processing level: " << pow(2, i) << std::endl;
std::ostringstream ltag;
ltag << pow(2,i);
DiskImageView<float> left_int("arctic/asp_al-L.crop."+ltag.str()+".tif"),
right_int("arctic/asp_al-R.crop."+ltag.str()+".tif");
ImageView<PixelMask<Vector2f> > sf_disparity_super =
2*crop(resample(sf_disparity,2,2), bounding_box(left_int));
sf_disparity = sf_disparity_super;
ImageView<float> right_t;
{
vw::Timer timer("Transform Right");
right_t =
block_rasterize
(transform(right_int,
stereo::DisparityTransform(sf_disparity)),
Vector2i(256, 256));
write_image("transformed"+ltag.str()+"-L.tif", left_int);
write_image("transformed"+ltag.str()+"-R.tif", right_t);
}
ImageView<PixelMask<Vector2f> > combined;
{
vw::Timer timer("Correlation Time");
pm_disparity =
block_rasterize
(stereo::correlate(left_int, right_t,
stereo::NullOperation(),
per_level_search,
Vector2i(13, 13), stereo::CROSS_CORRELATION, 2),
Vector2i(256, 256));
write_image("pmdelta"+ltag.str()+"-D.tif", pm_disparity);
combined = sf_disparity_super + pm_disparity;
write_image("patchmatch"+ltag.str()+"-D.tif", combined);
}
{
vw::Timer surface_timer("Surface Fitting time");
sf_disparity = block_rasterize(stereo::surface_fit(combined),
Vector2i(64, 64));
write_image("surface"+ltag.str()+"-D.tif", sf_disparity);
}
{
vw::Timer timer("Bluring");
copy_valid(sf_disparity, combined);
blur_disparity(sf_disparity, search_region/pow(2,i));
write_image("surface-blur"+ltag.str()+"-D.tif", sf_disparity);
}
}
// Final level .. I got lazy
DiskImageView<float> left1("arctic/asp_al-L.crop.tif"), right1("arctic/asp_al-R.crop.tif");
ImageView<PixelMask<Vector2f> > sf_disparity_super =
2 * crop(resample(sf_disparity, 2, 2), bounding_box(left1));
sf_disparity = sf_disparity_super;
ImageView<float> right1_t;
ImageView<PixelMask<Vector2f> > combined;
{
vw::Timer timer("Transform Right");
right1_t =
block_rasterize
(transform(right1,
stereo::DisparityTransform(sf_disparity)),
Vector2i(256, 256));
write_image("transformed1-L.tif", left1);
write_image("transformed1-R.tif", right1_t);
}
{
vw::Timer timer("Correlation Time");
pm_disparity =
block_rasterize
(stereo::correlate(left1, right1_t,
stereo::NullOperation(),
per_level_search,
Vector2i(13, 13), stereo::CROSS_CORRELATION, 2),
Vector2i(256, 256));
write_image("pmdelta1-D.tif", pm_disparity);
combined = sf_disparity_super + pm_disparity;
write_image("patchmatch1-D.tif", combined);
}
{
vw::Timer surface_timer("Surface Fitting time");
sf_disparity = block_rasterize(stereo::surface_fit(combined),
Vector2i(64, 64));
write_image("surface1-D.tif", sf_disparity);
}
{
vw::Timer timer("Bluring");
copy_valid(sf_disparity, combined);
blur_disparity(sf_disparity, search_region);
write_image("surface-blur1-D.tif", sf_disparity);
}
{
right1_t =
block_rasterize
(transform(right1,
stereo::DisparityTransform(sf_disparity)),
Vector2i(256, 256));
write_image("transformed1_2-L.tif", left1);
write_image("transformed1_2-R.tif", right1_t);
right1_t =
block_rasterize
(transform(right1,
stereo::DisparityTransform(combined)),
Vector2i(256, 256));
write_image("transformed1_2-TR.tif", right1_t);
}
return 0;
}