ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
gpu_mat_ref_image.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <memory>
11 
12 #include "mvs/cuda_texture.h"
13 #include "mvs/gpu_mat.h"
14 
15 namespace colmap {
16 namespace mvs {
17 
19 public:
20  GpuMatRefImage(const size_t width, const size_t height);
21 
22  // Filter image using sum convolution kernel to compute local sum of
23  // intensities. The filtered images can then be used for repeated, efficient
24  // NCC computation.
25  void Filter(const uint8_t* image_data,
26  const size_t window_radius,
27  const size_t window_step,
28  const float sigma_spatial,
29  const float sigma_color);
30 
31  // Image intensities.
32  std::unique_ptr<GpuMat<uint8_t>> image;
33 
34  // Local sum of image intensities.
35  std::unique_ptr<GpuMat<float>> sum_image;
36 
37  // Local sum of squared image intensities.
38  std::unique_ptr<GpuMat<float>> squared_sum_image;
39 
40 private:
41  const static size_t kBlockDimX = 16;
42  const static size_t kBlockDimY = 12;
43 
44  const size_t width_;
45  const size_t height_;
46 };
47 
49  __device__ BilateralWeightComputer(const float sigma_spatial,
50  const float sigma_color)
51  : spatial_normalization_(1.0f / (2.0f * sigma_spatial * sigma_spatial)),
52  color_normalization_(1.0f / (2.0f * sigma_color * sigma_color)) {}
53 
54  __device__ inline float Compute(const float row_diff,
55  const float col_diff,
56  const float color1,
57  const float color2) const {
58  const float spatial_dist_squared =
59  row_diff * row_diff + col_diff * col_diff;
60  const float color_dist = color1 - color2;
61  return exp(-spatial_dist_squared * spatial_normalization_ -
62  color_dist * color_dist * color_normalization_);
63  }
64 
65 private:
66  const float spatial_normalization_;
67  const float color_normalization_;
68 };
69 
70 } // namespace mvs
71 } // namespace colmap
int width
int height
std::unique_ptr< GpuMat< float > > sum_image
void Filter(const uint8_t *image_data, const size_t window_radius, const size_t window_step, const float sigma_spatial, const float sigma_color)
std::unique_ptr< GpuMat< uint8_t > > image
std::unique_ptr< GpuMat< float > > squared_sum_image
GpuMatRefImage(const size_t width, const size_t height)
__device__ BilateralWeightComputer(const float sigma_spatial, const float sigma_color)
__device__ float Compute(const float row_diff, const float col_diff, const float color1, const float color2) const