void EdgeRoberts::prepareMatrices() { g_x = math::matrix<double>(3,3); g_y = math::matrix<double>(3,3); g_x(0,0) = 1; g_x(0,1) = 0; g_x(1,0) = 0; g_x(1,1) = -1; g_y(0,0) = 0; g_y(0,1) = 1; g_y(1,0) = -1; g_y(1,1) = 0; }
double rhs_1st_equation (double x, double t, Gas_parameters * parameters) { return g_t (x, t) + .5 * ( 2 * u_exact (x, t) * g_x (x, t) + g_exact(x, t) * u_x (x, t) + (2 - g_exact (x, t)) * u_x (x, t)); }
std::vector<arma::mat> logcosh(arma::mat& x){ arma::mat gx = arma::tanh(x); arma::mat g_x(gx.n_rows, 1); for(int i=0; i<gx.n_rows; ++i){ arma::rowvec dtanh_i = 1 -arma::pow(gx.row(i),2); g_x.row(i) = arma::mean(dtanh_i); } std::vector<arma::mat> gx_dgx{gx,g_x}; return gx_dgx; };
void EdgeSobel::prepareMatrices() { g_x = math::matrix<double>(3,3); g_x(0,0)=-1; g_x(0,1)=0; g_x(0,2)=1; g_x(1,0)=-2; g_x(1,1)=0; g_x(1,2)=2; g_x(2,0)=-1; g_x(2,1)=0; g_x(2,2)=1; g_y = math::matrix<double>(3,3); g_y(0,0)=-1; g_y(0,1)=-2; g_y(0,2)=-1; g_y(1,0)=0; g_y(1,1)=0; g_y(1,2)=0; g_y(2,0)=1; g_y(2,1)=2; g_y(2,2)=1; }
static mode_t g_rwx(void) { return (g_r() | g_w() | g_x()); }
int main(int argc, char *argv[]) { if (argc != 4) { cout << "Usage: " << argv[0] << " cpu|gpu out_func out_prefix" << endl; return 1; } ImageParam input(UInt(8), 3, "input"); Func clamped("clamped"), grayscale("grayscale"); Func g_x("g_x"), g_y("g_y"), g_mag("g_mag"); Func sobel("sobel"); Var c("c"), x("x"), y("y"); // Algorithm clamped(x, y, c) = input( clamp(x, 0, input.width()-1), clamp(y, 0, input.height()-1), c) / 255.f; grayscale(x, y) = clamped(x, y, 0)*0.299f + clamped(x, y, 1)*0.587f + clamped(x, y, 2)*0.114f; Image<int16_t> kernel(3, 3); kernel(0, 0) = -1; kernel(0, 1) = -2; kernel(0, 2) = -1; kernel(1, 0) = 0; kernel(1, 1) = 0; kernel(1, 2) = 0; kernel(2, 0) = 1; kernel(2, 1) = 2; kernel(2, 2) = 1; RDom r(kernel); g_x(x, y) += kernel(r.x, r.y) * grayscale(x + r.x - 1, y + r.y - 1); g_y(x, y) += kernel(r.y, r.x) * grayscale(x + r.x - 1, y + r.y - 1); g_mag(x, y) = sqrt(g_x(x, y)*g_x(x, y) + g_y(x, y)*g_y(x, y)); sobel(x, y, c) = select(c==3, 255, u8(clamp(g_mag(x, y), 0, 1)*255)); // Channel order input.set_stride(0, 4); input.set_extent(2, 4); sobel.reorder_storage(c, x, y); sobel.output_buffer().set_stride(0, 4); sobel.output_buffer().set_extent(2, 4); // Schedules if (!strcmp(argv[1], "cpu")) { sobel.parallel(y).vectorize(c, 4); } else if (!strcmp(argv[1], "gpu")) { sobel.cuda_tile(x, y, 16, 4); } else { cout << "Invalid schedule type '" << argv[1] << "'" << endl; return 1; } compile(sobel, input, argv[2], argv[3]); return 0; }
template <typename PointInT, typename IntensityT> void pcl::tracking::PyramidalKLTTracker<PointInT, IntensityT>::computePyramids (const PointCloudInConstPtr& input, std::vector<FloatImageConstPtr>& pyramid, pcl::InterpolationType border_type) const { int step = 3; pyramid.resize (step * nb_levels_); FloatImageConstPtr previous; FloatImagePtr tmp (new FloatImage (input->width, input->height)); #ifdef _OPENMP #pragma omp parallel for num_threads (threads_) #endif for (int i = 0; i < static_cast<int> (input->size ()); ++i) tmp->points[i] = intensity_ (input->points[i]); previous = tmp; FloatImagePtr img (new FloatImage (previous->width + 2*track_width_, previous->height + 2*track_height_)); pcl::copyPointCloud (*tmp, *img, track_height_, track_height_, track_width_, track_width_, border_type, 0.f); pyramid[0] = img; // compute first level gradients FloatImagePtr g_x (new FloatImage (input->width, input->height)); FloatImagePtr g_y (new FloatImage (input->width, input->height)); derivatives (*img, *g_x, *g_y); // copy to bigger clouds FloatImagePtr grad_x (new FloatImage (previous->width + 2*track_width_, previous->height + 2*track_height_)); pcl::copyPointCloud (*g_x, *grad_x, track_height_, track_height_, track_width_, track_width_, pcl::BORDER_CONSTANT, 0.f); pyramid[1] = grad_x; FloatImagePtr grad_y (new FloatImage (previous->width + 2*track_width_, previous->height + 2*track_height_)); pcl::copyPointCloud (*g_y, *grad_y, track_height_, track_height_, track_width_, track_width_, pcl::BORDER_CONSTANT, 0.f); pyramid[2] = grad_y; for (int level = 1; level < nb_levels_; ++level) { // compute current level and current level gradients FloatImageConstPtr current; FloatImageConstPtr g_x; FloatImageConstPtr g_y; downsample (previous, current, g_x, g_y); // copy to bigger clouds FloatImagePtr image (new FloatImage (current->width + 2*track_width_, current->height + 2*track_height_)); pcl::copyPointCloud (*current, *image, track_height_, track_height_, track_width_, track_width_, border_type, 0.f); pyramid[level*step] = image; FloatImagePtr gradx (new FloatImage (g_x->width + 2*track_width_, g_x->height + 2*track_height_)); pcl::copyPointCloud (*g_x, *gradx, track_height_, track_height_, track_width_, track_width_, pcl::BORDER_CONSTANT, 0.f); pyramid[level*step + 1] = gradx; FloatImagePtr grady (new FloatImage (g_y->width + 2*track_width_, g_y->height + 2*track_height_)); pcl::copyPointCloud (*g_y, *grady, track_height_, track_height_, track_width_, track_width_, pcl::BORDER_CONSTANT, 0.f); pyramid[level*step + 2] = grady; // set the new level previous = current; } }
double rhs_2nd_equation (double x, double t, Gas_parameters * parameters) { return u_t (x, t) + u_exact (x, t) * u_x (x, t) + parameters->p_ro * g_x (x, t) - parameters->viscosity * exp (-g_exact (x, t)) * u_xx (x, t); }