Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef PCL_SURFACE_IMPL_BILATERAL_UPSAMPLING_H_
00042 #define PCL_SURFACE_IMPL_BILATERAL_UPSAMPLING_H_
00043
00044 #include <pcl/surface/bilateral_upsampling.h>
00045 #include <algorithm>
00046
00048 template <typename PointInT, typename PointOutT> void
00049 pcl::BilateralUpsampling<PointInT, PointOutT>::process (pcl::PointCloud<PointOutT> &output)
00050 {
00051
00052 output.header = input_->header;
00053
00054 if (!initCompute ())
00055 {
00056 output.width = output.height = 0;
00057 output.points.clear ();
00058 return;
00059 }
00060
00061 if (input_->isOrganized () == false)
00062 {
00063 PCL_ERROR ("Input cloud is not organized.\n");
00064 return;
00065 }
00066
00067
00068 unprojection_matrix_ = projection_matrix_.inverse ();
00069
00070 for (int i = 0; i < 3; ++i)
00071 {
00072 for (int j = 0; j < 3; ++j)
00073 printf ("%f ", unprojection_matrix_(i, j));
00074
00075 printf ("\n");
00076 }
00077
00078
00079
00080 performProcessing (output);
00081
00082 deinitCompute ();
00083 }
00084
00086 template <typename PointInT, typename PointOutT> void
00087 pcl::BilateralUpsampling<PointInT, PointOutT>::performProcessing (PointCloudOut &output)
00088 {
00089 output.resize (input_->size ());
00090 float nan = std::numeric_limits<float>::quiet_NaN ();
00091
00092
00093 for (int x = 0; x < static_cast<int> (input_->width); ++x)
00094 for (int y = 0; y < static_cast<int> (input_->height); ++y)
00095 {
00096 int start_window_x = std::max (x - window_size_, 0),
00097 start_window_y = std::max (y - window_size_, 0),
00098 end_window_x = std::min (x + window_size_, static_cast<int> (input_->width)),
00099 end_window_y = std::min (y + window_size_, static_cast<int> (input_->height));
00100
00101 float sum = 0.0f,
00102 norm_sum = 0.0f;
00103
00104 for (int x_w = start_window_x; x_w < end_window_x; ++ x_w)
00105 for (int y_w = start_window_y; y_w < end_window_y; ++ y_w)
00106 {
00107 float dx = float (x - x_w),
00108 dy = float (y - y_w);
00109
00110 float val_exp_depth = expf (- (dx*dx + dy*dy) / (2.0f * static_cast<float> (sigma_depth_ * sigma_depth_)));
00111
00112 float d_color = static_cast<float> (
00113 abs (input_->points[y_w * input_->width + x_w].r - input_->points[y * input_->width + x].r) +
00114 abs (input_->points[y_w * input_->width + x_w].g - input_->points[y * input_->width + x].g) +
00115 abs (input_->points[y_w * input_->width + x_w].b - input_->points[y * input_->width + x].b));
00116 float val_exp_rgb = expf (- d_color * d_color / (2.0f * sigma_color_ * sigma_color_));
00117
00118 if (pcl_isfinite (input_->points[y_w*input_->width + x_w].z))
00119 {
00120 sum += val_exp_depth * val_exp_rgb * input_->points[y_w*input_->width + x_w].z;
00121 norm_sum += val_exp_depth * val_exp_rgb;
00122 }
00123 }
00124
00125 output.points[y*input_->width + x].r = input_->points[y*input_->width + x].r;
00126 output.points[y*input_->width + x].g = input_->points[y*input_->width + x].g;
00127 output.points[y*input_->width + x].b = input_->points[y*input_->width + x].b;
00128
00129 if (norm_sum != 0.0f)
00130 {
00131 float depth = sum / norm_sum;
00132 Eigen::Vector3f pc (static_cast<float> (x) * depth, static_cast<float> (y) * depth, depth);
00133 Eigen::Vector3f pw (unprojection_matrix_ * pc);
00134 output.points[y*input_->width + x].x = pw[0];
00135 output.points[y*input_->width + x].y = pw[1];
00136 output.points[y*input_->width + x].z = pw[2];
00137 }
00138 else
00139 {
00140 output.points[y*input_->width + x].x = nan;
00141 output.points[y*input_->width + x].y = nan;
00142 output.points[y*input_->width + x].z = nan;
00143 }
00144 }
00145
00146 output.header = input_->header;
00147 output.width = input_->width;
00148 output.height = input_->height;
00149 }
00150
00151
00152
00153 #define PCL_INSTANTIATE_BilateralUpsampling(T,OutT) template class PCL_EXPORTS pcl::BilateralUpsampling<T,OutT>;
00154
00155
00156 #endif