Learn R Programming

ProFit (version 1.3.3)

profitConvolvePSF: High level image convolution

Description

A high level interface to fast convolution that takes a user supplied image and point spread function (PSF) as inputs. This routine calls lower level functions like profitBruteConv and also implements FFT-based convolution using either R's built-in FFT or the `fftw` interface to the FFTW library (the latter is usually significantly faster).

Usage

profitConvolvePSF(image, psf, calcregion, docalcregion=FALSE, 
  options=list(method="Bruteconv"), sky = 0, plot = FALSE, ...)

Arguments

image

The image matrix to be convolved by the point spread function (PSF).

psf

The point spread function (PSF) image matrix that ProFit will use to convolve the image. This can have odd sizes in each dimension. If the dimension has an even size then the function will internally interpolate it onto an odd sized grid 1 element larger. The PSF will be automatically rescaled so it sums to 1 before convolution to ensure flux conservation in the model.

options

Additional options for model convolution parsed as a list. option$method inputs allowed are Bruteconv (brute force convolution), FFTconv (FFT convolution using the R fft function) and FFTWconv (FFT using the FFTW library). If using FFTconv or FFTWconv you will also need to supply a fft list. In practice this is one of the list outputs of profitBenchmarkConv (see Examples).

calcregion

Logical matrix; logical image matrix the same size as the input image matrix. If docalcregion=TRUE, then pixels in calcregion that are TRUE (or 1) will have the convolution calculated, pixels with FALSE (or 0) values will be set to 0. This is included to increase computation speed in situations where only a small region of the full image contains the galaxy of interest for fitting. In this case pixels a long way from the segmentation region for the galaxy will not need to be convolved in order to calculate the correct likelihood within the segmentation.

docalcregion

Logical; should the calcregion logical matrix be used to define a subset of pixels to be convolved.

sky

Numeric scalar; the sky level of the image. This is important to ensure the convolution works well at the edges, since the padded regions outside the image bounds will be effectively set to the sky value. If this is much higher of lower than the true sky then you may see artefacts.

plot

Logical; should a magimage plot of the output be generated?

Further arguments to be passed to magimage. Only relevant is plot=TRUE.

Value

Matrix; convolved image matrix the same size as the input image matrix.

Details

In the regime where one image is significantly (a factor of a few) smaller than the other image, this tends to be faster than FFT based convolution due to the lack of image padding and other overheads. PSF images tend to be only dozens of pixels and images 100s, so brute force convolution is the standard approach used in ProFit. This function offers a convenient high level interface to link{profitBruteConv}, which can only accept odd size dimensions for the PSF.

See Also

profitBruteConv, profitMakePointSource, profitBenchmarkConv

Examples

Run this code
# NOT RUN {
model = list(
	sersic = list(
		xcen   = c(180, 60),
		ycen   = c(90, 10),
		mag = c(15, 13),
		re  = c(14, 5),
		nser  = c(3, 10),
		ang  = c(46, 80),
		axrat  = c(0.4, 0.6),
		box = c(0.5,-0.5)
	)
)

model.image=profitMakeModel(model=model, dim=c(200,200))$z

psf=profitMakeGaussianPSF()

#Do some benchmarking:

temp=profitBenchmarkConv(model.image, psf=psf)

#Check the best:

temp$best

#And we can use all three:

magimage(profitConvolvePSF(model.image, psf, options=list(method='Bruteconv')))
magimage(profitConvolvePSF(model.image, psf, options=list(method='FFTconv', fft=temp$fft)))
magimage(profitConvolvePSF(model.image, psf, options=list(method='FFTWconv', fft=temp$fft)))
# }

Run the code above in your browser using DataLab