include # flborder -- fill in the borders of an image # This task fills in each border by replicating the adjacent pixel value. # Values in the corner rectanges within the border region are assigned the # value of the adjacent corner pixel in the good region. Any or all of # the borders may be omitted by setting the width to zero. # # Phil Hodge, 5-Mar-1990 Task created. procedure flborder() pointer input # scratch for name of input image pointer output # scratch for name of output image int left_b # size of left border (in pixels) int right_b # size of right border int bottom_b # size of bottom border int top_b # size of top border #-- pointer sp real left_val # fill value for left border real right_val # fill value for right border pointer iim, oim # pointer to imhdr structs for input, output images pointer ix, ox # pointers to input, output data int line # loop index int k # loop index for left & right borders int naxis1, naxis2 # size of image bool inplace # true if input = output pointer immap(), imgl2r(), impl2r() int clgeti() bool streq() begin call smark (sp) call salloc (input, SZ_FNAME, TY_CHAR) call salloc (output, SZ_FNAME, TY_CHAR) # Get input parameters. call clgstr ("input", Memc[input], SZ_FNAME) call clgstr ("output", Memc[output], SZ_FNAME) left_b = clgeti ("left_b") right_b = clgeti ("right_b") bottom_b = clgeti ("bottom_b") top_b = clgeti ("top_b") if (streq (Memc[input], Memc[output]) || (Memc[output] == EOS)) { inplace = true call mktemp ("flattemp", Memc[output], SZ_FNAME) } else { inplace = false } # Open input image. iim = immap (Memc[input], READ_ONLY, NULL) naxis1 = IM_LEN(iim,1) naxis2 = IM_LEN(iim,2) if ((left_b + right_b >= naxis1) || (bottom_b + top_b >= naxis2)) { call imunmap (iim) call error (1, "borders are too large for size of image") } # Create output image. oim = immap (Memc[output], NEW_COPY, iim) # Fill bottom strip of output image with line bottom_b+1 from input. # Also fill left & right edges with values adjacent to border. ix = imgl2r (iim, bottom_b+1) left_val = Memr[ix+left_b] right_val = Memr[ix+naxis1-right_b-1] do line = 1, bottom_b { ox = impl2r (oim, line) call amovr (Memr[ix], Memr[ox], naxis1) # copy entire line # Fill left & right edges. do k = 0, left_b-1 # zero indexed Memr[ox+k] = left_val do k = naxis1-right_b, naxis1-1 # zero indexed Memr[ox+k] = right_val } # Copy input image to output, skipping bottom & top borders; # fill left & right edges. do line = bottom_b+1, naxis2-top_b { ix = imgl2r (iim, line) ox = impl2r (oim, line) call amovr (Memr[ix], Memr[ox], naxis1) # Fill left & right edges. left_val = Memr[ix+left_b] right_val = Memr[ix+naxis1-right_b-1] do k = 0, left_b-1 Memr[ox+k] = left_val do k = naxis1-right_b, naxis1-1 Memr[ox+k] = right_val } # Fill top strip of output image with line naxis2-top_b from input. ix = imgl2r (iim, naxis2-top_b) left_val = Memr[ix+left_b] right_val = Memr[ix+naxis1-right_b-1] do line = naxis2-top_b+1, naxis2 { ox = impl2r (oim, line) call amovr (Memr[ix], Memr[ox], naxis1) # Fill left & right edges. do k = 0, left_b-1 Memr[ox+k] = left_val do k = naxis1-right_b, naxis1-1 Memr[ox+k] = right_val } call imunmap (oim) call imunmap (iim) if (inplace) { call imdelete (Memc[input]) call imrename (Memc[output], Memc[input]) } call sfree (sp) end