18 #ifndef PIC_ALGORITHMS_LIVE_WIRE_HPP 19 #define PIC_ALGORITHMS_LIVE_WIRE_HPP 24 #include "../base.hpp" 26 #include "../image.hpp" 27 #include "../filtering/filter_luminance.hpp" 28 #include "../filtering/filter_gradient.hpp" 29 #include "../filtering/filter_log_2d_opt.hpp" 30 #include "../filtering/filter_channel.hpp" 31 #include "../filtering/filter_sampler_2d.hpp" 32 #include "../util/vec.hpp" 33 #include "../util/std_util.hpp" 60 tmp = (*fZ)(q[0], q[1]);
64 tmp = (*img_G)(q[0], q[1]);
67 float dist_qp = sqrtf(
float(q.distanceSq(p)));
68 out += 0.14f * fG / dist_qp;
73 tmp = (*img_G)(p[0], p[1]);
74 Vec2f D_p(tmp[1], -tmp[0]);
75 float n_D_p_sq = D_p.lengthSq();
77 D_p /= sqrtf(n_D_p_sq);
81 tmp = (*img_G)(q[0], q[1]);
82 Vec2f D_q(tmp[1], -tmp[0]);
83 float n_D_q_sq = D_q.lengthSq();
85 D_q /= sqrtf(n_D_q_sq);
89 Vec2f delta_qp(
float(q[0] - p[0]),
float(q[1] - p[1]));
92 if(D_p.dot(delta_qp) >= 0.0f) {
103 float dp_pq = D_p.dot(L);
104 float dq_pq = L.
dot(D_q);
106 float fD = (acosf(dp_pq) + acosf(dq_pq)) *
fD_const;
190 void execute(
Vec2i pS,
Vec2i pE, std::vector< Vec2i > &out,
bool bConstrained =
false,
bool bMultiple =
false)
201 int nx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
202 int ny[] = { 1, 1, 1, 0, 0, -1, -1, -1};
215 bX[0] =
MAX(
MIN(pS[0], pE[0]) - boundSize, -1);
216 bX[1] =
MIN(
MAX(pS[0], pE[0]) + boundSize, width);
218 bY[0] =
MAX(
MIN(pS[1], pE[1]) - boundSize, -1);
219 bY[1] =
MIN(
MAX(pS[1], pE[1]) + boundSize, height);
222 tmp = (*g)(pS[0], pS[1]);
225 std::vector< Vec2i > list;
228 while(!list.empty()) {
229 std::vector< Vec2i >::iterator index;
234 for(
auto it = list.begin(); it != list.end(); it++) {
235 float g_it = (*g)((*it)[0], (*it)[1])[0];
253 int index_q = q[1] * width + q[0];
256 for(
int i = 0; i < 8; i++) {
257 Vec2i r(q[0] + nx[i], q[1] + ny[i]);
259 if((r[0] > bX[0]) && (r[0] < bX[1]) &&
260 (r[1] > bY[0]) && (r[1] < bY[1])) {
262 if(!
e[r[1] * width + r[0]]) {
263 float g_tmp = g_q +
getCost(q, r);
267 for(
auto it = list.begin(); it != list.end(); it++) {
274 if(bFlag && (g_tmp < g_q)) {
279 tmp = (*g)(r[0], r[1]);
282 int index = (r[1] * width + r[0]);
303 int maxIter = (width * height);
306 while((!prev.
equal(m)) && (i < maxIter)) {
313 int index = (m[1] * width + m[0]);
338 lw->
execute(pS, pE, out,
true,
false);
355 for(
auto i = 0; i < (controlPoints.size() - 1); i++) {
356 lw->
execute(controlPoints.at(i), controlPoints.at(i + 1), out,
true,
true);
static void executeLiveWireSingle(Image *in, Vec2i pS, Vec2i pE, std::vector< Vec2i > &out)
executeLiveWireSingle
Definition: live_wire.hpp:333
float * fG_max
Definition: live_wire.hpp:42
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
int * pointers
Definition: live_wire.hpp:45
void execute(Vec2i pS, Vec2i pE, std::vector< Vec2i > &out, bool bConstrained=false, bool bMultiple=false)
execute
Definition: live_wire.hpp:190
bool * e
Definition: live_wire.hpp:46
float * fG_min
Definition: live_wire.hpp:42
const float C_PI
Definition: math.hpp:50
float * getMinVal(BBox *box, float *ret)
getMinVal computes the minimum value for the current Image.
Image * g
Definition: live_wire.hpp:44
Image * img_G
Definition: live_wire.hpp:44
static Image * execute(Image *imgIn, Image *imgOut=NULL, GRADIENT_TYPE type=G_SOBEL, int colorChannel=0)
execute
Definition: filter_gradient.hpp:89
int nPixels() const
nPixels computes the number of pixels.
Definition: image.hpp:499
float fD_const
Definition: live_wire.hpp:40
static void executeLiveWireMultiple(Image *in, std::vector< Vec2i > &controlPoints, std::vector< Vec2i > &out)
executeLiveWireMultiple
Definition: live_wire.hpp:350
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
void applyFunction(float(*func)(float))
applyFunction is an operator that applies an input function to all values in data.
LiveWire(Image *img)
Definition: live_wire.hpp:137
T dot(Vec< N, T > a)
dot
Definition: vec.hpp:276
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Image * fZ
Definition: live_wire.hpp:44
Definition: live_wire.hpp:37
Definition: bilateral_separation.hpp:25
bool equal(Vec< N, T > a)
equal
Definition: vec.hpp:203
#define MAX(a, b)
Definition: math.hpp:73
void release()
release
Definition: live_wire.hpp:116
static float f1minusx(float x)
f1minusx
Definition: live_wire.hpp:130
float * getMaxVal(BBox *box, float *ret)
getMaxVal computes the maximum value for the current Image.
int width
Definition: image.hpp:80
float getCost(Vec2i &p, Vec2i &q)
getCost
Definition: live_wire.hpp:54
int height
Definition: image.hpp:80
T lengthSq()
lengthSq
Definition: vec.hpp:335
static Image * execute(Image *imgIn, Image *imgOut, float sigma)
execute
Definition: filter_log_2d_opt.hpp:51
~LiveWire()
Definition: live_wire.hpp:150
The Vec class.
Definition: vec.hpp:35
static T * assign(T *buffer, int n, T value)
assign assigns value to buffer
Definition: buffer.hpp:45