# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. include include # lin_boxcar -- convolve an image # The kernel dimensions are assumed to be odd. # This was taken from cnv_boxcar in images$filters/boxcar.x. The only # change was to put the output in an array instead of an image. procedure lin_boxcar (im, smooth, ncols, nlines, nxk, nyk, boundary, constant) pointer im # i: pointer to the input image real smooth[ncols,nlines] # o: smoothed image int ncols, nlines # i: size of smoothed image int nxk, nyk # i: dimensions of the kernel int boundary # i: type of boundary extnsion real constant # i: constant for constant boundary extension #-- int i, col1, col2, inline, outline pointer sp, lineptrs, accum pointer v, imgl2r() # used for copying without smoothing pointer imgs2r() errchk imgs2r begin if (nxk == 1 && nyk == 1) { # No smoothing; just copy the image to the output array. do outline = 1, min (IM_LEN(im,2), nlines) { v = imgl2r (im, outline) call amovr (Memr[v], smooth[1,outline], min (IM_LEN(im,1), ncols)) } if (ncols > IM_LEN(im,1)) { do outline = 1, nlines { call amovkr (0., smooth[IM_LEN(im,1)+1,outline], ncols - IM_LEN(im,1)) } } if (nlines > IM_LEN(im,2)) { do outline = IM_LEN(im,2)+1, nlines call amovkr (0., smooth[1,outline], ncols) } return } # Set input image column limits col1 = 1 - nxk / 2 col2 = IM_LEN(im,1) + nxk / 2 # Set up an array of linepointers and accumulators call smark (sp) call salloc (lineptrs, nyk, TY_POINTER) call salloc (accum, ncols + nxk - 1, TY_REAL) # Set boundary conditions on input image call imseti (im, IM_NBUFS, nyk) call imseti (im, IM_TYBNDRY, boundary) call imseti (im, IM_NBNDRYPIX, max (nxk / 2 + 1, nyk / 2 + 1)) if (boundary == BT_CONSTANT) call imsetr (im, IM_BNDRYPIXVAL, constant) # Clear the accumulator call aclrr (Memr[accum], ncols + nxk - 1) # Initialize the accumulator inline = 1 - nyk / 2 do i = 1, nyk - 1 { Memi[lineptrs+i] = imgs2r (im, col1, col2, inline, inline) call aaddr (Memr[accum], Memr[Memi[lineptrs+i]], Memr[accum], ncols + nxk - 1) inline = inline + 1 } # Generate the remaining image lines image line by line do outline = 1, nlines { # Scroll buffers do i = 1, nyk - 1 Memi[lineptrs+i-1] = Memi[lineptrs+i] # Read in new image line, accumulate Memi[lineptrs+nyk-1] = imgs2r (im, col1, col2, inline, inline) call aaddr (Memr[accum], Memr[Memi[lineptrs+nyk-1]], Memr[accum], ncols + nxk - 1) # Write output line. call lin_aboxr (Memr[accum], smooth[1,outline], ncols, nxk) call adivkr (smooth[1,outline], real (nxk * nyk), smooth[1,outline], ncols) # Subtract last line call asubr (Memr[accum], Memr[Memi[lineptrs]], Memr[accum], ncols + nxk - 1) inline = inline + 1 } # Free buffers call sfree (sp) end # lin_aboxr -- Vector boxcar smooth. # This was taken from cnv_aboxr in images$filters/aboxcar.x. No change # was made except for the name. procedure lin_aboxr (in, out, npix, knpix) real in[npix+knpix-1] real out[npix] int npix, knpix int i real sum begin sum = 0.0 do i = 1, knpix - 1 sum = sum + in[i] do i = 1, npix { sum = sum + in[i+knpix-1] out[i] = sum sum = sum - in[i] } end