PRO dical_interp, img, loc, VERT=vert, MAXSIZE=maxsize, FLAGS=flags $ , Fail2DBlobs=fail2db ;;----------------------------------------------------------------------------- ;; PURPOSE: ;; Performs thin plate spline interpolation across segments of the given ;; image. At the edges, pixels are repeated, instead of extrapolated. ;; ;; CALLING SEQUENCE: ;; DICal_interp, img, loc, /VERT ;; ;; REQUIRED INPUTS: ;; img - The image to perform the interpolation on ;; loc - result of a WHERE call specifiying where to interpolate over ;; ;; OUTPUTS: ;; The image with the areas interpolated over ;; ;; OPTIONAL INPUT KEYWORDS: ;; VERT - only interpolate in the vertical direction. Used for IR images. ;; MAXSIZE - the maximum size of a region to interpolate over in 2D interpolation ;; FLAGS - flags identifying where the invalid pixels are ;; ;; OPTIONAL OUTPUT KEYWORDS: ;; FAIL2DBLOBS - 0b on success, 1b if too many flagged pixels for find_2Dblobs to work. ;; ;; EXAMPLE: ;; IDL> dical_interp, in, loc ;; ;; PROCEDURES USED (i.e. called directly!): ;; find_2Dblobs ;; ;; MODIFICATION HISTORY: ;; 2004-08-19 M. Desnoyer Created ;; ;;----------------------------------------------------------------------------- @dical_flags img = double(img) dim = size(img, /dimensions) IF NOT keyword_set(maxSize) THEN maxSize = 9999 fail2db=0b ;;; assume success IF size(loc, /n_dimension) EQ 0 THEN RETURN ;; Nothing to interpolate over ;; Determine where the invalid data resides badData = where(flags NE 0) IF keyword_set(VERT) THEN BEGIN ;; 1D interpolation along the columns img = dical_irinterp(img,loc,badData) ;; Modify the flags flags[loc] = flags[loc] OR FLAG_INTERP ENDIF ELSE BEGIN ;; 2D Interpolation ;; Figure out where the edges are X = loc mod dim[0] Y = loc / dim[0] edge = where((X EQ 0) OR (Y EQ 0) OR (X EQ dim[0]-1) OR (Y EQ dim[1]-1), cnt,$ complement=w, ncomplement=compCnt) IF cnt GT 0 THEN BEGIN ;; Fill in the edges, for now, just use the ir routine because we ;; there will only be holes that can be filled using the vertical and ;; development time is limited. THIS MAY BE REVISITED img = dical_irinterp(img,loc[edge],badData) ;; Update the flag map flags[loc[edge]] = flags[loc[edge]] OR FLAG_INTERP ;; Update the pixels that need interpolation IF compCnt EQ 0 THEN RETURN loc = loc[w] ENDIF ;; Group the gaps by size gaps = find_2DBlobs(loc, dim[0], SIZE=gapSize, Fail2DBlobs=fail2db) if fail2db THEN RETURN ;; find_2DBlobs failed; do nothing ;; Remove the gaps that are too big justRight = where((gapSize[0,*]