64 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
68 std::optional<beliefprop::BpRunOutput>
operator()(
const std::array<std::string, 2>& ref_test_image_path,
76 void msg(
float s1[DISP_VALS],
float s2[DISP_VALS],
float s3[DISP_VALS],
float s4[DISP_VALS],
77 float dst[DISP_VALS],
float disc_k_bp)
const;
78 void dt(
float f[DISP_VALS])
const;
90 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
92 for (
unsigned int q = 1; q < DISP_VALS; q++) {
93 float prev = f[q - 1] + 1.0F;
97 for (
int q = (
int)DISP_VALS - 2; q >= 0; q--) {
98 float prev = f[q + 1] + 1.0F;
105 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
107 float s2[DISP_VALS],
float s3[DISP_VALS],
108 float s4[DISP_VALS],
float dst[DISP_VALS],
109 float disc_k_bp)
const {
113 float minimum = beliefprop::kHighValBp<float>;
114 for (
unsigned int value = 0; value < DISP_VALS; value++) {
115 dst[value] = s1[value] + s2[value] + s3[value] + s4[value];
116 if (dst[value] < minimum)
117 minimum = dst[value];
124 minimum += disc_k_bp;
125 for (
unsigned int value = 0; value < DISP_VALS; value++)
126 if (minimum < dst[value])
127 dst[value] = minimum;
131 for (
unsigned int value = 0; value < DISP_VALS; value++)
135 for (
unsigned int value = 0; value < DISP_VALS; value++)
140 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
143 unsigned int width{(
unsigned int)img1->
width()};
144 unsigned int height{(
unsigned int)img1->
height()};
152 sm1 = imageUCHARtoFLOAT(img1);
153 sm2 = imageUCHARtoFLOAT(img2);
156 for (
unsigned int y = 0; y < height; y++) {
157 for (
unsigned int x = DISP_VALS - 1; x < width; x++) {
158 for (
unsigned int value = 0; value < DISP_VALS; value++) {
159 const float val =
abs(
imRef(sm1, x, y) -
imRef(sm2, x - value, y));
171 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
175 unsigned int width{(
unsigned int)data->
width()};
176 unsigned int height{(
unsigned int)data->
height()};
179 for (
unsigned int y = 1; y < height - 1; y++) {
180 for (
unsigned int x = 1; x < width - 1; x++) {
182 unsigned int best = 0;
183 float best_val = beliefprop::kHighValBp<float>;
184 for (
unsigned int value = 0; value < DISP_VALS; value++) {
186 imRef(u, x, y+1)[value] +
187 imRef(d, x, y-1)[value] +
188 imRef(l, x+1, y)[value] +
189 imRef(r, x-1, y)[value] +
190 imRef(data, x, y)[value];
192 if (val < best_val) {
197 imRef(out, x, y) = best;
205 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
209 unsigned int width{(
unsigned int)data->
width()};
210 unsigned int height{(
unsigned int)data->
height()};
212 for (
unsigned int t = 0; t < iter; t++) {
213 for (
unsigned int y = 1; y < height - 1; y++) {
214 for (
unsigned int x = ((y + t) % 2) + 1; x < width - 1; x += 2) {
217 imRef(data, x, y),
imRef(u, x, y), disc_k_bp);
220 imRef(data, x, y),
imRef(d, x, y), disc_k_bp);
223 imRef(data, x, y),
imRef(r, x, y), disc_k_bp);
226 imRef(data, x, y),
imRef(l, x, y), disc_k_bp);
234 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
243 auto timeStart = std::chrono::system_clock::now();
246 data[0] = comp_data(img1, img2, alg_settings);
249 for (
unsigned int i = 1; i < alg_settings.
num_levels; i++) {
250 const unsigned int old_width = (
unsigned int)data[i - 1]->width();
251 const unsigned int old_height = (
unsigned int)data[i - 1]->height();
252 const unsigned int new_width = (
unsigned int)ceil(old_width / 2.0);
253 const unsigned int new_height = (
unsigned int)ceil(old_height / 2.0);
255 assert(new_width >= 1);
256 assert(new_height >= 1);
259 for (
unsigned int y = 0; y < old_height; y++) {
260 for (
unsigned int x = 0; x < old_width; x++) {
261 for (
unsigned int value = 0; value < DISP_VALS; value++) {
262 imRef(data[i], x/2, y/2)[value] +=
263 imRef(data[i-1], x, y)[value];
270 for (
int i = alg_settings.
num_levels - 1; i >= 0; i--) {
271 unsigned int width = (
unsigned int)data[i]->width();
272 unsigned int height = (
unsigned int)data[i]->height();
275 if ((
unsigned int)i == (alg_settings.
num_levels - 1)) {
288 for (
unsigned int y = 0; y < height; y++) {
289 for (
unsigned int x = 0; x < width; x++) {
290 for (
unsigned int value = 0; value < DISP_VALS; value++) {
291 imRef(u[i], x, y)[value] =
292 imRef(u[i+1], x/2, y/2)[value];
293 imRef(d[i], x, y)[value] =
294 imRef(d[i+1], x/2, y/2)[value];
295 imRef(l[i], x, y)[value] =
296 imRef(l[i+1], x/2, y/2)[value];
297 imRef(r[i], x, y)[value] =
298 imRef(r[i+1], x/2, y/2)[value];
316 auto timeEnd = std::chrono::system_clock::now();
317 runtime = timeEnd-timeStart;
328 return {out, run_data};
331 template<
typename T,
unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
342 img1 = loadPGMOrPPMImage(ref_test_image_path[0].c_str());
343 img2 = loadPGMOrPPMImage(ref_test_image_path[1].c_str());
347 std::chrono::duration<double> runtime;
348 const auto [output_disp_map, output_run_data] = stereo_ms(img1, img2, alg_settings, runtime);
353 output->run_data = output_run_data;
354 output->out_disparity_map =
356 std::array<unsigned int, 2>{(
unsigned int)img1->
width(), (
unsigned int)img1->
height()});
359 for (
unsigned int y = 0; y < (
unsigned int)img1->
height(); y++) {
360 for (
unsigned int x = 0; x < (
unsigned int)img1->
width(); x++) {
368 delete output_disp_map;
File with namespace for enums, constants, structures, and functions specific to belief propagation pr...
Header file that contains information about the stereo sets used for evaluation of the bp implementat...
Declares child class of ParallelParams to store and process parallelization parameters to use in each...
Declares abstract class to set up and run belief propagation on target device using specified acceler...
Declares and defines structure that stores settings for current implementation run as well as functio...
void SetPixelAtPoint(const std::array< unsigned int, 2 > &point_xy, T val)
Abstract class for holding and processing parallelization parameters. Child class(es) specific to im...
Abstract class to set up and run belief propagation on target device using specified acceleration.
Child class of RunBpOnStereoSet to run single-threaded CPU implementation of belief propagation on a ...
std::optional< beliefprop::BpRunOutput > operator()(const std::array< std::string, 2 > &ref_test_image_path, const beliefprop::BpSettings &alg_settings, const ParallelParams ¶llel_params) const override
Pure virtual operator() overload that must be defined in child class.
std::string BpRunDescription() const override
Pure virtual function to return run description corresponding to target acceleration.
Class to store headers with data corresponding to current program run and evaluation.
void AddDataWHeader(const std::string &header, const std::string &data)
Add string data with header describing added data.
static image< float > * smooth(image< float > *src, float sigma)
constexpr std::string_view kSingleThreadRuntimeHeader
Structure with output disparity map, runtime, and other evaluation data.
std::chrono::duration< double > run_time
Structure to store the belief propagation settings including the number of levels and iterations.
unsigned int num_iterations
float disc_k_bp
Discontinuity cost cap set to high value by default but is expected to be dependent on number of disp...