imProc.background - EranOfek/AstroPack GitHub Wiki

Description

The imProc.background package include functions to estimate the background and variance of astronomical images stored in an AstroImage objects.

Functions

  • imProc.background.allFunList - Functions and Classes list for the imProc.background package
  • imProc.background.background - Calculate the background and variance of an AstroImage object.
  • imProc.background.filterSources - Generate a background image filtered from sources using successive filtering
  • imProc.background.fitSurface - Fit a surface to a 2D image, with sigma clipping
  • imProc.background.subtractMeanColRow - Subtract the collapsed median of rows and columns from an AstroImage.
  • imProc.background.unitTest - unitTest for the +imProc.background package

imProc.background.background

This function can be used to estimate the background and variance of images. This function works on AstroImage objects, and it uses the imUtil.background.background (in the imUtil package).

The following operation creates a random image in an AstroImage object, and estimates its background and variance. The background and variance are stored in the BackData and VarData properties of the AstroImage object, and they accessible as matrices or scalars in the Back and Var properties of the AstroImage object:

% Create a random image with std of 1 and background of 100:
AI = AstroImage({randn(1024,1024)+100});
AI = imProc.background.background(AI);

You can control the background and variance estimation method:

AI = imProc.background.background(AI, 'BackFun',@median);

Another important parameter that can be controlled is 'SubSizeXY' which sets the sub-image size in which the background and variance are estimated. The background is estimated as a scalar in each such sub-image in a grid, and then interpolated to the entire image:

% Where 128 and 128 are the sub-image size and overlap is the overlap between sub-images:
AI = imProc.background.background(AI, 'SubSizeXY',[128 128],'Overlap',12);

To subtract the background from an image, and to recalculate it if it does not exist, you can use the subtractBackground method of AstroImage.

AI=AI.subtractBackground;
AI=AI.subtractBackground('backgroundArgs',{'SubSizeXY',[]});

imProc.background.subtractMeanColRow

This function subtracts the collapsed median of rows and columns from an AstroImage. This function may be useful in order to remove lines correlated noise from images. The function works on AstroImage objects and it is implemented using the imUtil.background.subtractMeanColRow in the imUtil package.

AI = AstroImage({rand(1600,1600)});
AI = imProc.background.subtractMeanColRow(AI)

imProc.background.fitSurface

Fit a polynomial surface to images in AstroImage object. The function returns both the fit parameters and the fitted surfcae.

% create a surface image:
[MatX, MatY] = meshgrid( (1:1:1000), (1:1:1000) );
Z = 2+MatX +MatY + MatX.*MatY;
% store it in AstroImage:
AI = AstroImage({Z});
% Fit a surface:
[Result, Surface] = imProc.background.fitSurface(AI)

% Another example:
VecX = (11:10:990).';
VecY = VecX;
[MatX, MatY] = meshgrid( VecX, VecY);
Z = 2+MatX +MatY + MatX.*MatY;
AI = AstroImage({Z});
[Result, Surface] = imProc.background.fitSurface(AI, 'SizeIJ',[1000 1000], 'VecX',VecX, 'VecY',VecY);    

imProc.background.filterSources

Generate a background image filtered from sources using successive filtering The image is populated in the Back field or returned as a BackImage object.

% Read a FITS image into an AstroImage object:
AI=AstroImage('PTF_Cropped.fits');
% Convert to double and multiply by the gain:
AI=cast(AI,'double'); AI.Image = AI.Image.*1.6;
% filter sources and estimate the back and variance.
imProc.background.filterSources(AI);

The Back and Var are stored in the input AstroImage object.