texture_2d tangent_flow_map(const texture_2d& src, float sigma) { texture_2d tmp0(src.clone_format()); texture_2d tmp1(src.clone_format()); texture_2d dst(src.clone_format()); glsl_program sst("sst_fs.glsl"); sst.use(); sst.bind_sampler("img", src); sst.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); sst.draw(&tmp0); glsl_program gauss("gauss_fs.glsl"); gauss.use(); gauss.bind_sampler("img", tmp0); gauss.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); gauss.set_uniform_1f("sigma", sigma); gauss.draw(&tmp1); glsl_program tfm("tfm_fs.glsl"); tfm.use(); tfm.bind_sampler("img", tmp1); tfm.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); tfm.draw(&dst); return dst; }
texture_2d smooth_filter(const texture_2d& tfm, const texture_2d& img, int type, float sigma) { texture_2d dst(tfm.clone_format()); if (type == 3) { glsl_program glsl("lic_fs.glsl"); glsl.use(); glsl.bind_sampler("tfm", tfm); glsl.bind_sampler("img", img); glsl.set_uniform_1f("sigma", sigma); glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); glsl.draw(&dst); } else { glsl_program gauss((type == 1)? "gauss3x3_fs.glsl" : "gauss5x5_fs.glsl"); gauss.use(); gauss.bind_sampler("img", img); gauss.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); gauss.draw(&dst); } return dst; }
texture_2d color_quantization(const texture_2d& img, int nbins, float phi_q, int filter) { texture_2d dst(img.clone_format()); texture_2d tmp(img.clone_format()); glsl_program cq("color_quantization_fs.glsl"); cq.use(); cq.bind_sampler("img", img); cq.set_uniform_1i("nbins", nbins); cq.set_uniform_1f("phi_q", phi_q); cq.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); cq.draw(&tmp); if (filter) { glsl_program gauss((filter == 1)? "gauss3x3_fs.glsl" : "gauss5x5_fs.glsl"); gauss.use(); gauss.bind_sampler("img", tmp); gauss.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); gauss.draw(&dst); } else { dst = tmp; } return dst; }
texture_2d fdog_filter(const texture_2d& src, const texture_2d& tfm, int n, float sigma_e, float sigma_r, float tau, float sigma_m, float phi) { texture_2d tmp(src.clone_format()); texture_2d dst(src.clone_format()); for (int i = 0; i < n; ++i) { texture_2d img = (i == 0)? src : overlay(dst, src); glsl_program fdog0("fdog0_fs.glsl"); fdog0.use(); fdog0.bind_sampler("img", img, GL_LINEAR); fdog0.bind_sampler("tfm", tfm, GL_NEAREST); fdog0.set_uniform_1f("sigma_e", sigma_e); fdog0.set_uniform_1f("sigma_r", sigma_r); fdog0.set_uniform_1f("tau", tau); fdog0.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); fdog0.draw(&tmp); glsl_program fdog1("fdog1_fs.glsl"); fdog1.use(); fdog1.bind_sampler("img", tmp, GL_LINEAR); fdog1.bind_sampler("tfm", tfm, GL_NEAREST); fdog1.set_uniform_1f("sigma_m", sigma_m); fdog1.set_uniform_1f("phi", phi); fdog1.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); fdog0.draw(&dst); } return dst; }
texture_2d orientation_aligned_bilateral_filter(const texture_2d& src, const texture_2d& tfm, int n, float sigma_d, float sigma_r) { texture_2d tmp(src.clone_format()); texture_2d dst(src.clone_format()); glsl_program glsl("bf_fs.glsl"); glsl.use(); glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); glsl.set_uniform_1f("sigma_d", sigma_d); glsl.set_uniform_1f("sigma_r", sigma_r); glsl.bind_sampler("tfm", tfm); for (int i = 0; i < n; ++i) { glsl.bind_sampler("img", (i == 0)? src : dst, GL_LINEAR); glsl.set_uniform_1i("pass", 0); glsl.draw(&tmp); glsl.bind_sampler("img", tmp, GL_LINEAR); glsl.set_uniform_1i("pass", 1); glsl.draw(&dst); } return dst; }
texture_2d lab2rgb(const texture_2d& src) { glsl_program glsl("lab2rgb_fs.glsl"); texture_2d dst(src.clone_format()); glsl.use(); glsl.bind_sampler("img", src); glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); glsl.draw(&dst); return dst; }
texture_2d gauss_filter(const texture_2d& src, float sigma) { glsl_program glsl("gauss_fs.glsl"); texture_2d dst(src.clone_format()); glsl.use(); glsl.bind_sampler("img", src); glsl.set_uniform_1f("sigma", sigma); glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); glsl.draw(&dst); return dst; }
texture_2d overlay(const texture_2d& edges, const texture_2d& img) { texture_2d dst(edges.clone_format()); glsl_program glsl("overlay_fs.glsl"); glsl.use(); glsl.bind_sampler("edges", edges); glsl.bind_sampler("img", img); glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); glsl.draw(&dst); return dst; }
texture_2d mix_filter(const texture_2d& edges, const texture_2d& img, float edge_color[3]) { texture_2d dst(edges.clone_format()); glsl_program glsl("mix_fs.glsl"); glsl.use(); glsl.bind_sampler("edges", edges); glsl.bind_sampler("img", img); glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); glsl.set_uniform_3f("edge_color", edge_color[0], edge_color[1], edge_color[2]); glsl.draw(&dst); return dst; }
texture_2d lic_filter(const texture_2d& tfm, const texture_2d& img, float sigma) { texture_2d dst(tfm.clone_format()); glsl_program glsl("lic_fs.glsl"); glsl.use(); glsl.bind_sampler("tfm", tfm); glsl.bind_sampler("img", img); glsl.set_uniform_1f("sigma", sigma); glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height()); glsl.draw(&dst); return dst; }
texture_2d dog_filter(const texture_2d& src, int n, float sigma_e, float sigma_r, float tau, float phi) { texture_2d tmp(src.clone_format()); //texture_2d dst(src.clone_format()); for (int i = 0; i < n; ++i) { texture_2d img = (i == 0)? src : overlay(tmp, src); glsl_program dog("dog_fs.glsl"); dog.use(); dog.bind_sampler("img", img, GL_NEAREST); dog.set_uniform_1f("sigma_e", sigma_e); dog.set_uniform_1f("sigma_r", sigma_r); dog.set_uniform_1f("tau", tau); dog.set_uniform_1f("phi", phi); dog.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); dog.draw(&tmp); } return tmp; }