//computes the energy of the pixel at x,y and updates the max energy if needed double energy(int x, int y) { double result = sqrt(pow(gradx(x, y), 2) + pow(grady(x, y), 2)); if (result > max_energy) { max_energy = result; } return result; }
//computes the energy of the pixel at x,y and updates the max energy if needed double energy(int x, int y) { double result = sqrt(pow(gradx(x, y), 2) + pow(grady(x, y), 2)); /* maximum energy communication results in a serious slowdown and does not have a major effect on the resulting image quality */ if (result > my_max_energy) { my_max_energy = result; } return result; }
static void compute_lic (GimpDrawable *drawable, const guchar *scalarfield, gboolean rotate) { gint xcount, ycount; GimpRGB color; gdouble vx, vy, tmp; GimpPixelRgn src_rgn, dest_rgn; gimp_pixel_rgn_init (&src_rgn, drawable, border_x, border_y, border_w, border_h, FALSE, FALSE); gimp_pixel_rgn_init (&dest_rgn, drawable, border_x, border_y, border_w, border_h, TRUE, TRUE); for (ycount = 0; ycount < src_rgn.h; ycount++) { for (xcount = 0; xcount < src_rgn.w; xcount++) { /* Get derivative at (x,y) and normalize it */ /* ============================================================== */ vx = gradx (scalarfield, xcount, ycount); vy = grady (scalarfield, xcount, ycount); /* Rotate if needed */ if (rotate) { tmp = vy; vy = -vx; vx = tmp; } tmp = sqrt (vx * vx + vy * vy); if (tmp >= 0.000001) { tmp = 1.0 / tmp; vx *= tmp; vy *= tmp; } /* Convolve with the LIC at (x,y) */ /* ============================== */ if (licvals.effect_convolve == 0) { peek (&src_rgn, xcount, ycount, &color); tmp = lic_noise (xcount, ycount, vx, vy); if (source_drw_has_alpha) gimp_rgba_multiply (&color, tmp); else gimp_rgb_multiply (&color, tmp); } else { lic_image (&src_rgn, xcount, ycount, vx, vy, &color); } poke (&dest_rgn, xcount, ycount, &color); } gimp_progress_update ((gfloat) ycount / (gfloat) src_rgn.h); } gimp_progress_update (1.0); }
/** * @brief Detection of a X corner in the imput image * @param in - input image float * @param ptx - approximate x coord. of the X corner; (output) refined position * @param pty - approximate y coord. of the X corner; (output) refined position * @return int - 0 if no error */ static int detect_xcorner(ImageFloat in, float *ptx, float *pty) { ImageFloat mask, src_buff, gx_buff, gy_buff; float coeff; int i, j, k, y, x; float cx = *ptx; float cy = *pty; float c2x, c2y; int max_iters = 400; float eps = 0.00001; int wsize = 3; float a11, a12, a22, p, q, d; int iter = 0; float err; float py, px; float tgx, tgy, gxx, gxy, gyy, m; float *mask1D; /*mask1D = new_vector(2*wsize+1); */ mask1D = (float *) malloc((2 * wsize + 1) * sizeof(float)); mask = new_imageFloat(2 * wsize + 1, 2 * wsize + 1); coeff = 1. / (mask->ncol * mask->nrow); /* calculate mask */ for (i = -wsize, k = 0; i <= wsize; i++, k++) { mask1D[k] = exp(-i * i * coeff); } for (i = 0; i < (int) mask->nrow; i++) { for (j = 0; j < (int) mask->ncol; j++) { mask->val[i * mask->nrow + j] = mask1D[j] * mask1D[i]; } } do { src_buff = extract_subpx_window(in, wsize, cx, cy); gx_buff = gradx(src_buff); gy_buff = grady(src_buff); a11 = a12 = a22 = p = q = 0; /* process gradient */ for (y = -wsize, k = 0; y <= wsize; y++) { py = cy + (float) y; for (x = -wsize; x <= wsize; x++, k++) { m = mask->val[k]; tgx = gx_buff->val[k]; tgy = gy_buff->val[k]; gxx = tgx * tgx * m; gxy = tgx * tgy * m; gyy = tgy * tgy * m; px = cx + (float) x; a11 += gxx; a12 += gxy; a22 += gyy; p += gxx * px + gxy * py; q += gxy * px + gyy * py; } } d = a11 * a22 - a12 * a12; c2x = 1 / d * (a22 * p - a12 * q); c2y = 1 / d * (-a12 * p + a11 * q); err = dist_l2(cx, cy, c2x, c2y); cx = c2x; cy = c2y; free_imageFloat(src_buff); free_imageFloat(gx_buff); free_imageFloat(gy_buff); } while (++iter < max_iters && err > eps); *ptx = cx; *pty = cy; free_imageFloat(mask); free((void *) mask1D); return 0; }