pro get_bg, data, bg, region=region, degree=degree, margin=f ; + ; NAME : get_bg ; PURPOSE : ; Generate background component from a given image ; CALLING SEQUENCE ; get_bg, data, bg, region=region, degree=degree, margin=margin ; INPUT ; data : one- or two-dimensional data array ; OPTIONAL KEYWORD INPUT ; REGION The index array of the data points to be used in the ; fitting ; DEGREE The degree of polynomials adopted in the fitting ; (default=1) ; MARGIN The fractionional position of marginal points to be used ; in the fitting when REGION is not specified (default=0.1) ; OUTPUT ; bg : one- or two-dimensional array of background ; REQUIRED SUBROUTINES ; XYINDEX ; HISTORY ; Chae, Jong-Chul : April, 1996 ;- on_error, 1 s=size(data) if not keyword_set(degree) then degree=1 if undefined(f) then f=0.1 case s(0) of 1 : begin x1 = findgen(s(1)) if not keyword_set(region) then begin a1 = s(1)*0.1 a2 = s(1)*0.9 region = where((x1-a1)*(x1-a2) ge 0.) endif xo = float(x1(region)) yo = data(region) coeff=poly_fit(xo, yo, degree) bg = 0. for i=0, degree do bg = bg+coeff(i)*x1^i end 2 : begin xyindex, data, x1, y1 x1=float(x1) y1=float(y1) if not keyword_set(region) then begin a1=n_elements(data(*,0))*f a2=n_elements(data(*,0))*(1-f) b1=n_elements(data(0,*))*f b2=n_elements(data(0,*))*(1-f) region = $ where((x1-a1)*(x1-a2) ge 0. or (y1-b1)*(y1-b2) ge 0.) endif xo=x1(region)*1.0 yo=y1(region)*1.0 ao=data(region) polywarp,ao,ao,xo,yo,degree,k1,k2 bg = 0. for i=0,degree do for j=0, degree do bg = bg + k1(i,j)*x1^j*y1^i end endcase return end