/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; File: convolve.c ;;; Author: Eero Simoncelli ;;; Description: General convolution code for 2D images ;;; Creation Date: Spring, 1987. ;;; MODIFICATIONS: ;;; 10/89: approximately optimized the choice of register vars on SPARCS. ;;; 6/96: Switched array types to double float. ;;; 2/97: made more robust and readable. Added STOP arguments. ;;; 8/97: Bug: when calling internal_reduce with edges in {reflect1,repeat, ;;; extend} and an even filter dimension. Solution: embed the filter ;;; in the upper-left corner of a filter with odd Y and X dimensions. ;;; ---------------------------------------------------------------- ;;; Object-Based Vision and Image Understanding System (OBVIUS), ;;; Copyright 1988, Vision Science Group, Media Laboratory, ;;; Massachusetts Institute of Technology. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ #include #include #include "convolve.h" /* -------------------------------------------------------------------- Correlate FILT with IMAGE, subsampling according to START, STEP, and STOP parameters, with values placed into RESULT array. RESULT dimensions should be ceil((stop-start)/step). TEMP should be a pointer to a temporary double array the size of the filter. EDGES is a string specifying how to handle boundaries -- see edges.c. The convolution is done in 9 sections, where the border sections use specially computed edge-handling filters (see edges.c). The origin of the filter is assumed to be (floor(x_fdim/2), floor(y_fdim/2)). ------------------------------------------------------------------------ */ /* abstract out the inner product computation */ #define INPROD(XCNR,YCNR) \ { \ sum=0.0; \ for (im_pos=YCNR*x_dim+XCNR, filt_pos=0, x_filt_stop=x_fdim; \ x_filt_stop<=filt_size; \ im_pos+=(x_dim-x_fdim), x_filt_stop+=x_fdim) \ for (; \ filt_pos