summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-04-26 09:31:21 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-04-26 09:43:16 +0200
commitd2dd6636ce6298fce17c72b91a48c0d9db630db3 (patch)
tree3b96523a28438cf4a8267a14963e6344c19529a9
parentcdeae0b80c9722861b14c81198488590762b8467 (diff)
downloadcv-d2dd6636ce6298fce17c72b91a48c0d9db630db3.zip
cv-d2dd6636ce6298fce17c72b91a48c0d9db630db3.tar.gz
cv-d2dd6636ce6298fce17c72b91a48c0d9db630db3.tar.bz2
harris: Fix convolution clamping
-rw-r--r--harris.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/harris.c b/harris.c
index 502e976..1099f61 100644
--- a/harris.c
+++ b/harris.c
@@ -50,8 +50,8 @@ grey_scale(GdkPixbuf *image)
int *
conv(GdkPixbuf *pixbuf, gint *operator, gint block_size)
{
- gint Y, i, j, x, y, width, height, nch, stride;
- guchar *p, *row, *v;
+ gint Y, i, j, ci, cj, x, y, width, height, nch, stride;
+ guchar *p, *row, v;
int *out;
pixbuf_get(pixbuf, &row, &width, &height, &nch, &stride);
@@ -62,12 +62,13 @@ conv(GdkPixbuf *pixbuf, gint *operator, gint block_size)
for (y = 0; y < height; ++y, row += stride) {
for (x = 0, p = row; x < width; ++x, p += nch) {
Y = 0;
- for (i = 0; i < block_size; ++i) {
- for (j = 0; j < block_size; ++j) {
- /* TODO: fix clamping */
- v = p + (CLAMP((j-block_size/2), 0, width-1) * stride +
- CLAMP((i-block_size/2), 0, height-1) * nch);
- Y += v[0] * operator[j*block_size + i];
+ for (j = 0; j < block_size; ++j) {
+ cj = CLAMP(j - block_size/2, -y, height-1-y);
+ for (i = 0; i < block_size; ++i) {
+ ci = CLAMP(i - block_size/2, -x, width-1-x);
+
+ v = p[cj * stride + ci * nch + 0];
+ Y += v * operator[j*block_size + i];
}
}
out[y * width + x] = Y/4;