gnuastro (0.22)
This is gnuastro.info, produced by makeinfo version 7.1 from
gnuastro.texi.
This book documents version 0.22 of the GNU Astronomy Utilities
(Gnuastro). Gnuastro provides various programs and libraries for
astronomical data manipulation and analysis.
Copyright © 2015-2024 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts, and
no Back-Cover Texts. A copy of the license is included in the
section entitled "GNU Free Documentation License".
INFO-DIR-SECTION Astronomy
START-INFO-DIR-ENTRY
* Gnuastro: (gnuastro). GNU Astronomy Utilities.
* libgnuastro: (gnuastro)Gnuastro library. Full Gnuastro library doc.
* help-gnuastro: (gnuastro)help-gnuastro mailing list. Getting help.
* bug-gnuastro: (gnuastro)Report a bug. How to report bugs
* Arithmetic: (gnuastro)Arithmetic. Arithmetic operations on pixels.
* astarithmetic: (gnuastro)Invoking astarithmetic. Options to Arithmetic.
* BuildProgram: (gnuastro)BuildProgram. Compile and run programs using Gnuastro's library.
* astbuildprog: (gnuastro)Invoking astbuildprog. Options to BuildProgram.
* ConvertType: (gnuastro)ConvertType. Convert different file types.
* astconvertt: (gnuastro)Invoking astconvertt. Options to ConvertType.
* Convolve: (gnuastro)Convolve. Convolve an input file with kernel.
* astconvolve: (gnuastro)Invoking astconvolve. Options to Convolve.
* CosmicCalculator: (gnuastro)CosmicCalculator. For cosmological params.
* astcosmiccal: (gnuastro)Invoking astcosmiccal. Options to CosmicCalculator.
* Crop: (gnuastro)Crop. Crop region(s) from image(s).
* astcrop: (gnuastro)Invoking astcrop. Options to Crop.
* Fits: (gnuastro)Fits. View and manipulate FITS extensions and keywords.
* astfits: (gnuastro)Invoking astfits. Options to Fits.
* MakeCatalog: (gnuastro)MakeCatalog. Make a catalog from labeled image.
* astmkcatalog: (gnuastro)Invoking astmkcatalog. Options to MakeCatalog.
* MakeProfiles: (gnuastro)MakeProfiles. Make mock profiles.
* astmkprof: (gnuastro)Invoking astmkprof. Options to MakeProfiles.
* Match: (gnuastro)Match. Match two separate catalogs.
* astmatch: (gnuastro)Invoking astmatch. Options to Match.
* NoiseChisel: (gnuastro)NoiseChisel. Detect signal in noise.
* astnoisechisel: (gnuastro)Invoking astnoisechisel. Options to NoiseChisel.
* Segment: (gnuastro)Segment. Segment detections based on signal structure.
* astsegment: (gnuastro)Invoking astsegment. Options to Segment.
* Query: (gnuastro)Query. Access remote databases for downloading data.
* astquery: (gnuastro)Invoking astquery. Options to Query.
* Statistics: (gnuastro)Statistics. Get image Statistics.
* aststatistics: (gnuastro)Invoking aststatistics. Options to Statistics.
* Table: (gnuastro)Table. Read and write FITS binary or ASCII tables.
* asttable: (gnuastro)Invoking asttable. Options to Table.
* Warp: (gnuastro)Warp. Warp a dataset to a new grid.
* astwarp: (gnuastro)Invoking astwarp. Options to Warp.
* astscript: (gnuastro)Installed scripts. Gnuastro's installed scripts.
* astscript-ds9-region: (gnuastro)Invoking astscript-ds9-region. Options to this script
* astscript-fits-view: (gnuastro)Invoking astscript-fits-view. Options to this script
* astscript-pointing-simulate: (gnuastro)Invoking astscript-pointing-simulate. Options to this script
* astscript-psf-scale-factor: (gnuastro)Invoking astscript-psf-scale-factor. Options to this script
* astscript-psf-select-stars: (gnuastro)Invoking astscript-psf-select-stars. Options to this script
* astscript-psf-stamp: (gnuastro)Invoking astscript-psf-stamp. Options to this script
* astscript-psf-subtract: (gnuastro)Invoking astscript-psf-subtract. Options to this script
* astscript-psf-unite: (gnuastro)Invoking astscript-psf-unite. Options to this script
* astscript-radial-profile: (gnuastro)Invoking astscript-radial-profile. Options to this script
* astscript-sort-by-night: (gnuastro)Invoking astscript-sort-by-night. Options to this script
* astscript-zeropoint: (gnuastro)Invoking astscript-zeropoint. Options to this script
END-INFO-DIR-ENTRY
File: gnuastro.info, Node: Operand storage in memory or a file, Prev: Building new dataset and stack management, Up: Arithmetic operators
6.2.4.21 Operand storage in memory or a file
............................................
In your early days of using Gnuastro, to do multiple operations, it is
likely that you will simply call Arithmetic (or Table, with column
arithmetic) multiple times: feed the output file of the first call to
the second call. But as you get more proficient in the reverse polish
notation, you will find yourself combining many operations into one
call. This greatly speeds up your operation, because instead of writing
the dataset to a file in one command, and reading it in the next
command, it will just keep the intermediate dataset in memory!
But adding more complexity to your operations, can make them much
harder to debug, or extend even further. Therefore in this section we
have some special operators that behave differently from the rest: they
do not touch the contents of the data, only where/how they are stored.
They are designed to do complex operations, without necessarily having a
complex command.
‘set-AAA’
Set the characters after the dash (‘AAA’ in the case shown here) as
a name for the first popped operand on the stack. The named
dataset will be freed from memory as soon as it is no longer
needed, or if the name is reset to refer to another dataset later
in the command. This operator thus enables reusability of a
dataset without having to reread it from a file every time it is
necessary during a process. When a dataset is necessary more than
once, this operator can thus help simplify reading/writing on the
command-line (thus avoiding potential bugs), while also speeding up
the processing.
Like all operators, this operator pops the top operand off of the
main processing stack, but unlike other operands, it will not add
anything back to the stack immediately. It will keep the popped
dataset in memory through a separate list of named datasets (not on
the main stack). That list will be used to add/copy any requested
dataset to the main processing stack when the name is called.
The name to give the popped dataset is part of the operator's name.
For example, the ‘set-a’ operator of the command below, gives the
name "‘a’" to the contents of ‘image.fits’. This name is then used
instead of the actual filename to multiply the dataset by two.
$ astarithmetic image.fits set-a a 2 x
The name can be any string, but avoid strings ending with standard
filename suffixes (for example, ‘.fits’)(1).
One example of the usefulness of this operator is in the ‘where’
operator. For example, let's assume you want to mask all pixels
larger than ‘5’ in ‘image.fits’ (extension number 1) with a NaN
value. Without setting a name for the dataset, you have to read
the file two times from memory in a command like this:
$ astarithmetic image.fits image.fits 5 gt nan where -g1
But with this operator you can simply give ‘image.fits’ the name
‘i’ and simplify the command above to the more readable one below
(which greatly helps when the filename is long):
$ astarithmetic image.fits set-i i i 5 gt nan where
‘repeat’
Add N copies of the second popped operand to the stack of operands.
N is the first popped operand. For example, let's assume
‘image.fits’ is a $100\times100$ image. The output of the command
below will be a 3D datacube of size $100\times100\times20$ voxels
(volume-pixels):
$ astarithmetic image.fits 20 repeat 20 add-dimension-slow
‘tofile-AAA’
Write the top operand on the operands stack into a file called
‘AAA’ (can be any FITS file name) without changing the operands
stack. If you do not need the dataset any more and would like to
free it, see the ‘tofilefree’ operator below.
By default, any file that is given to this operator is deleted
before Arithmetic actually starts working on the input datasets.
The deletion can be deactivated with the ‘--dontdelete’ option (as
in all Gnuastro programs, see *note Input output options::). If
the same FITS file is given to this operator multiple times, it
will contain multiple extensions (in the same order that it was
called.
For example, the operator ‘tofile-check.fits’ will write the top
operand to ‘check.fits’. Since it does not modify the operands
stack, this operator is very convenient when you want to debug, or
understanding, a string of operators and operands given to
Arithmetic: simply put ‘tofile-AAA’ anywhere in the process to see
what is happening behind the scenes without modifying the overall
process.
‘tofilefree-AAA’
Similar to the ‘tofile’ operator, with the only difference that the
dataset that is written to a file is popped from the operand stack
and freed from memory (cannot be used any more).
---------- Footnotes ----------
(1) A dataset name like ‘a.fits’ (which can be set with ‘set-a.fits’)
will cause confusion in the initial parser of Arithmetic. It will
assume this name is a FITS file, and if it is used multiple times,
Arithmetic will abort, complaining that you have not provided enough
HDUs.
File: gnuastro.info, Node: Invoking astarithmetic, Prev: Arithmetic operators, Up: Arithmetic
6.2.5 Invoking Arithmetic
-------------------------
Arithmetic will do pixel to pixel arithmetic operations on the
individual pixels of input data and/or numbers. For the full list of
operators with explanations, please see *note Arithmetic operators::.
Any operand that only has a single element (number, or single pixel FITS
image) will be read as a number, the rest of the inputs must have the
same dimensions. The general template is:
$ astarithmetic [OPTION...] ASTRdata1 [ASTRdata2] OPERATOR ...
One line examples:
## Calculate (10.32-3.84)^2.7 quietly (will just print 155.329):
$ astarithmetic -q 10.32 3.84 - 2.7 pow
## Inverse the input image (1/pixel):
$ astarithmetic 1 image.fits / --out=inverse.fits
## Multiply each pixel in image by -1:
$ astarithmetic image.fits -1 x --out=negative.fits
## Subtract extension 4 from extension 1 (counting from zero):
$ astarithmetic image.fits image.fits - --out=skysub.fits \
--hdu=1 --hdu=4
## Add two images, then divide them by 2 (2 is read as floating point):
## Note that without the '.0', the '2' will be read/used as an integer.
$ astarithmetic image1.fits image2.fits + 2.0 / --out=average.fits
## Use Arithmetic's average operator:
$ astarithmetic image1.fits image2.fits average --out=average.fits
## Calculate the median of three images in three separate extensions:
$ astarithmetic img1.fits img2.fits img3.fits median \
-h0 -h1 -h2 --out=median.fits
Arithmetic's notation for giving operands to operators is fully
described in *note Reverse polish notation::. The output dataset is
last remaining operand on the stack. When the output dataset a single
number, and ‘--output’ is not called, it will be printed on the standard
output (command-line). When the output is an array, it will be stored
as a file.
The name of the final file can be specified with the ‘--output’
option, but if it is not given (and the output dataset has more than one
element), Arithmetic will use "automatic output" on the name of the
first FITS image encountered to generate an output file name, see *note
Automatic output::. By default, if the output file already exists, it
will be deleted before Arithmetic starts operation. However, this can
be disabled with the ‘--dontdelete’ option (see below). At any point
during Arithmetic's operation, you can also write the top operand on the
stack to a file, using the ‘tofile’ or ‘tofilefree’ operators, see *note
Arithmetic operators::.
By default, the world coordinate system (WCS) information of the
output dataset will be taken from the first input image (that contains a
WCS) on the command-line. This can be modified with the ‘--wcsfile’ and
‘--wcshdu’ options described below. When the ‘--quiet’ option is not
given, the name and extension of the dataset used for the output's WCS
is printed on the command-line.
Through operators like those starting with ‘collapse-’, the
dimensionality of the inputs may not be the same as the outputs. By
default, when the output is 1D, Arithmetic will write it as a table, not
an image/array. The format of the output table (plain text or FITS
ASCII or binary) can be set with the ‘--tableformat’ option, see *note
Input output options::). You can disable this feature (write 1D arrays
as FITS images/arrays, or to the standard output) with the
‘--onedasimage’ or ‘--onedonstdout’ options.
See *note Common options:: for a review of the options in all
Gnuastro programs. Arithmetic just redefines the ‘--hdu’ and
‘--dontdelete’ options as explained below.
‘--arguments=STR’
A plain-text file containing the command-line arguments that will
be used by Arithmetic. This option is only relevant when no
arguments are given on the command-line: if any arguments are
given, this option is ignored.
This is necessary when the set of of input files and operators
(arguments; see *note Arguments and options::) are very long
(thousands of long file names for example; usually generated within
large pipelines). Such long arguments will cause the shell to
abort with an ‘Argument list too long’ error. In such cases, you
can put the list into a plain-text file and use this option like
below (assuming you want to stack all the files in a certain
directory with the ‘mean’ operator; see *note Stacking
operators::):
$ counter=0;
$ for f in $(pwd)/*.fits; do \
echo $f; counter=$((counter+1)); \
done > arguments.txt; \
echo "$counter mean" >> arguments.txt
$ astarithmetic --arguments=list.txt -g1
‘-h INT/STR’
‘--hdu INT/STR’
The header data unit of the input FITS images, see *note Input
output options::. Unlike most options in Gnuastro (which will
ultimately only have one value for this option), Arithmetic allows
‘--hdu’ to be called multiple times and the value of each
invocation will be stored separately (for the unlimited number of
input images you would like to use). Recall that for other
programs this (common) option only takes a single value. So in
other programs, if you specify it multiple times on the
command-line, only the last value will be used and in the
configuration files, it will be ignored if it already has a value.
The order of the values to ‘--hdu’ has to be in the same order as
input FITS images. Options are first read from the command-line
(from left to right), then top-down in each configuration file, see
*note Configuration file precedence::.
If the number of HDUs is less than the number of input images,
Arithmetic will abort and notify you. However, if there are more
HDUs than FITS images, there is no problem: they will be used in
the given order (every time a FITS image comes up on the stack) and
the extra HDUs will be ignored in the end. So there is no problem
with having extra HDUs in the configuration files and by default
several HDUs with a value of ‘0’ are kept in the system-wide
configuration file when you install Gnuastro.
‘-g INT/STR’
‘--globalhdu INT/STR’
Use the value to this option as the HDU of all input FITS files.
This option is very convenient when you have many input files and
the dataset of interest is in the same HDU of all the files. When
this option is called, any values given to the ‘--hdu’ option
(explained above) are ignored and will not be used.
‘-w FITS’
‘--wcsfile FITS’
FITS Filename containing the WCS structure that must be written to
the output. The HDU/extension should be specified with ‘--wcshdu’.
When this option is used, the respective WCS will be read before
any processing is done on the command-line and directly used in the
final output. If the given file does not have any WCS, then the
default WCS (first file on the command-line with WCS) will be used
in the output.
This option will mostly be used when the default file (first of the
set of inputs) is not the one containing your desired WCS. But with
this option, you can also use Arithmetic to rewrite/change the WCS
of an existing FITS dataset from another file:
$ astarithmetic data.fits --wcsfile=other.fits -ofinal.fits
‘-W STR’
‘--wcshdu STR’
HDU/extension to read the WCS within the file given to ‘--wcsfile’.
For more, see the description of ‘--wcsfile’.
‘--envseed’
Use the environment for the random number generator settings in
operators that need them (for example, ‘mknoise-sigma’). This is
very important for obtaining reproducible results, for more see
*note Generating random numbers::.
‘-n STR’
‘--metaname=STR’
Metadata (name) of the output dataset. For a FITS image or table,
the string given to this option is written in the ‘EXTNAME’ or
‘TTYPE1’ keyword (respectively).
If this keyword is present in a FITS extension, it will be printed
in the table output of a command like ‘astfits image.fits’ (for
images) or ‘asttable table.fits -i’ (for tables). This metadata
can be very helpful for yourself in the future (when you have
forgotten the details), so it is recommended to use this option for
files that should be archived or shared with colleagues.
‘-u STR’
‘--metaunit=STR’
Metadata (units) of the output dataset. For a FITS image or table,
the string given to this option is written in the ‘BUNIT’ or
‘TTYPE1’ keyword respectively. In the case of tables, recall that
the Arithmetic program only outputs a single column, you should use
column arithmetic in Table for more than one column (see *note
Column arithmetic::). For more on the importance of metadata, see
the description of ‘--metaname’.
‘-c STR’
‘--metacomment=STR’
Metadata (comments) of the output dataset. For a FITS image or
table, the string given to this option is written in the ‘COMMENT’
or ‘TCOMM1’ keyword respectively. In the case of tables, recall
that the Arithmetic program only outputs a single column, you
should use column arithmetic in Table for more than one column (see
*note Column arithmetic::). For more on the importance of
metadata, see the description of ‘--metaname’.
‘-O’
‘--onedasimage’
Write final dataset as a FITS image/array even if it has a single
dimension. By default, if the output is 1D, it will be written as
a table, see above. If the output has more than one dimension,
this option is redundant.
‘-s’
‘--onedonstdout’
Write final dataset (only when it is 1D) to standard output, not as
a file. By default 1D datasets will be written as a table, see
above. If the output has more than one dimension, this option is
redundant.
‘-D’
‘--dontdelete’
Do not delete the output file, or files given to the ‘tofile’ or
‘tofilefree’ operators, if they already exist. Instead append the
desired datasets to the extensions that already exist in the
respective file. Note it does not matter if the final output file
name is given with the ‘--output’ option, or determined
automatically.
Arithmetic treats this option differently from its default
operation in other Gnuastro programs (see *note Input output
options::). If the output file exists, when other Gnuastro
programs are called with ‘--dontdelete’, they simply complain and
abort. But when Arithmetic is called with ‘--dontdelete’, it will
appended the dataset(s) to the existing extension(s) in the file.
‘-a’
‘--writeall’
Write all datasets on the stack as separate HDUs in the output
file. This only affects datasets with multiple dimensions (or
single-dimension datasets when the ‘--onedasimg’ is called). This
option is useful to debug Arithmetic calls: to check all the images
on the stack while you are designing your operation. The top
dataset on the stack will be on HDU number 1 of the output, the
second dataset will be on HDU number 2 and so on.
Arithmetic accepts two kinds of input: images and numbers. Images
are considered to be any of the inputs that is a file name of a
recognized type (see *note Arguments::) and has more than one
element/pixel. Numbers on the command-line will be read into the
smallest type (see *note Numeric data types::) that can store them, so
‘-2’ will be read as a ‘char’ type (which is signed on most systems and
can thus keep negative values), ‘2500’ will be read as an ‘unsigned
short’ (all positive numbers will be read as unsigned), while
‘3.1415926535897’ will be read as a ‘double’ and ‘3.14’ will be read as
a ‘float’. To force a number to be read as float, put a ‘.’ after it
(possibly followed by a zero for easier readability), or add an ‘f’
after it. Hence while ‘5’ will be read as an integer, ‘5.’, ‘5.0’ or
‘5f’ will be added to the stack as ‘float’ (see *note Reverse polish
notation::).
Unless otherwise stated (in *note Arithmetic operators::), the
operators can deal with numeric multiple data types (see *note Numeric
data types::). For example, in "‘a.fits b.fits +’", the image types can
be ‘long’ and ‘float’. In such cases, C's internal type conversion will
be used. The output type will be set to the higher-ranking type of the
two inputs. Unsigned integer types have smaller ranking than their
signed counterparts and floating point types have higher ranking than
the integer types. So the internal C type conversions done in the
example above are equivalent to this piece of C:
size_t i;
long a[100];
float b[100], out[100];
for(i=0;i<100;++i) out[i]=a[i]+b[i];
Relying on the default C type conversion significantly speeds up the
processing and also requires less RAM (when using very large images).
Some operators can only work on integer types (of any length, for
example, bitwise operators) while others only work on floating point
types, (currently only the ‘pow’ operator). In such cases, if the
operand type(s) are different, an error will be printed. Arithmetic
also comes with internal type conversion operators which you can use to
convert the data into the appropriate type, see *note Arithmetic
operators::.
The hyphen (‘-’) can be used both to specify options (see *note
Options::) and also to specify a negative number which might be
necessary in your arithmetic. In order to enable you to do this,
Arithmetic will first parse all the input strings and if the first
character after a hyphen is a digit, then that hyphen is temporarily
replaced by the vertical tab character which is not commonly used. The
arguments are then parsed and these strings will not be specified as an
option. Then the given arguments are parsed and any vertical tabs are
replaced back with a hyphen so they can be read as negative numbers.
Therefore, as long as the names of the files you want to work on, do not
start with a vertical tab followed by a digit, there is no problem. An
important consequence of this implementation is that you should not
write negative fractions like this: ‘-.3’, instead write them as ‘-0.3’.
Without any images, Arithmetic will act like a simple calculator and
print the resulting output number on the standard output like the first
example above. If you really want such calculator operations on the
command-line, AWK (GNU AWK is the most common implementation) is much
faster, easier and much more powerful. For example, the numerical
one-line example above can be done with the following command. In
general AWK is a fantastic tool and GNU AWK has a wonderful manual
(<https://www.gnu.org/software/gawk/manual/>). So if you often confront
situations like this, or have to work with large text tables/catalogs,
be sure to checkout AWK and simplify your life.
$ echo "" | awk '{print (10.32-3.84)^2.7}'
155.329
File: gnuastro.info, Node: Convolve, Next: Warp, Prev: Arithmetic, Up: Data manipulation
6.3 Convolve
============
On an image, convolution can be thought of as a process to blur or
remove the contrast in an image. If you are already familiar with the
concept and just want to run Convolve, you can jump to *note Convolution
kernel:: and *note Invoking astconvolve:: and skip the lengthy
introduction on the basic definitions and concepts of convolution.
There are generally two methods to convolve an image. The first and
more intuitive one is in the "spatial domain" or using the actual image
pixel values, see *note Spatial domain convolution::. The second method
is when we manipulate the "frequency domain", or work on the magnitudes
of the different frequencies that constitute the image, see *note
Frequency domain and Fourier operations::. Understanding convolution in
the spatial domain is more intuitive and thus recommended if you are
just starting to learn about convolution. However, getting a good grasp
of the frequency domain is a little more involved and needs some
concentration and some mathematical proofs. However, its reward is a
faster operation and more importantly a very fundamental understanding
of this very important operation.
Convolution of an image will generally result in blurring the image
because it mixes pixel values. In other words, if the image has sharp
differences in neighboring pixel values(1), those sharp differences will
become smoother. This has very good consequences in detection of signal
in noise for example. In an actual observed image, the variation in
neighboring pixel values due to noise can be very high. But after
convolution, those variations will decrease and we have a better hope in
detecting the possible underlying signal. Another case where
convolution is extensively used is in mock images and modeling in
general, convolution can be used to simulate the effect of the
atmosphere or the optical system on the mock profiles that we create,
see *note PSF::. Convolution is a very interesting and important topic
in any form of signal analysis (including astronomical observations).
So we have thoroughly(2) explained the concepts behind it in the
following sub-sections.
* Menu:
* Spatial domain convolution:: Only using the input image values.
* Frequency domain and Fourier operations:: Using frequencies in input.
* Spatial vs. Frequency domain:: When to use which?
* Convolution kernel:: How to specify the convolution kernel.
* Invoking astconvolve:: Options and argument to Convolve.
---------- Footnotes ----------
(1) In astronomy, the only major time we confront such sharp borders
in signal are cosmic rays. All other sources of signal in an image are
already blurred by the atmosphere or the optics of the instrument.
(2) A mathematician will certainly consider this explanation is
incomplete and inaccurate. However this text is written for an
understanding on the operations that are done on a real (not complex,
discrete and noisy) astronomical image, not any general form of abstract
function
File: gnuastro.info, Node: Spatial domain convolution, Next: Frequency domain and Fourier operations, Prev: Convolve, Up: Convolve
6.3.1 Spatial domain convolution
--------------------------------
The pixels in an input image represent different "spatial" positions,
therefore when convolution is done only using the actual input pixel
values, we name the process as being done in the "Spatial domain". In
particular this is in contrast to the "frequency domain" that we will
discuss later in *note Frequency domain and Fourier operations::. In
the spatial domain (and in realistic situations where the image and the
convolution kernel do not extend to infinity), convolution is the
process of changing the value of one pixel to the _weighted_ average of
all the pixels in its _neighborhood_.
The 'neighborhood' of each pixel (how many pixels in which direction)
and the 'weight' function (how much each neighboring pixel should
contribute depending on its position) are given through a second image
which is known as a "kernel"(1).
* Menu:
* Convolution process:: More basic explanations.
* Edges in the spatial domain:: Dealing with the edges of an image.
---------- Footnotes ----------
(1) Also known as filter, here we will use 'kernel'.
File: gnuastro.info, Node: Convolution process, Next: Edges in the spatial domain, Prev: Spatial domain convolution, Up: Spatial domain convolution
6.3.1.1 Convolution process
...........................
In convolution, the kernel specifies the weight and positions of the
neighbors of each pixel. To find the convolved value of a pixel, the
central pixel of the kernel is placed on that pixel. The values of each
overlapping pixel in the kernel and image are multiplied by each other
and summed for all the kernel pixels. To have one pixel in the center,
the sides of the convolution kernel have to be an odd number. This
process effectively mixes the pixel values of each pixel with its
neighbors, resulting in a blurred image compared to the sharper input
image.
Formally, convolution is one kind of linear 'spatial filtering' in
image processing texts. If we assume that the kernel has $2a+1$ and
$2b+1$ pixels on each side, the convolved value of a pixel placed at $x$
and $y$ ($C_{x,y}$) can be calculated from the neighboring pixel values
in the input image ($I$) and the kernel ($K$) from
$$C_{x,y}=\sum_{s=-a}^{a}\sum_{t=-b}^{b}K_{s,t}\times{}I_{x+s,y+t}.$$
Formally, any pixel that is outside of the image in the equation
above will be considered to be zero (although, see *note Edges in the
spatial domain::). When the kernel is symmetric about its center the
blurred image has the same orientation as the original image. However,
if the kernel is not symmetric, the image will be affected in the
opposite manner, this is a natural consequence of the definition of
spatial filtering. In order to avoid this we can rotate the kernel
about its center by 180 degrees so the convolved output can have the
same original orientation (this is done by default in the Convolve
program). Technically speaking, only if the kernel is flipped the
process is known as _Convolution_. If it is not it is known as
_Correlation_.
To be a weighted average, the sum of the weights (the pixels in the
kernel) has to be unity. This will have the consequence that the
convolved image of an object and unconvolved object will have the same
brightness (see *note Brightness flux magnitude::), which is natural,
because convolution should not eat up the object photons, it only
disperses them.
The convolution of each pixel is independent of the other pixels, and
in some cases, it may be necessary to convolve different parts of an
image separately (for example, when you have different amplifiers on the
CCD). Therefore, to speed up spatial convolution, Gnuastro first defines
a tessellation over the input; assigning each group of pixels to
"tiles". It then does the convolution in parallel on each tile. For
more on how Gnuastro's programs create the tile grid (tessellation), see
*note Tessellation::.
File: gnuastro.info, Node: Edges in the spatial domain, Prev: Convolution process, Up: Spatial domain convolution
6.3.1.2 Edges in the spatial domain
...................................
In purely 'linear' spatial filtering (convolution), there are problems
with the edges of the input image. Here we will explain the problem in
the spatial domain. For a discussion of this problem from the frequency
domain perspective, see *note Edges in the frequency domain::. The
problem originates from the fact that on the edges, in practice, the sum
of the weights we use on the actual image pixels is not unity(1). For
example, as discussed above, a profile in the center of an image will
have the same brightness before and after convolution. However, for
partially imaged profile on the edge of the image, the brightness (sum
of its pixel fluxes within the image, see *note Brightness flux
magnitude::) will not be equal, some of the flux is going to be 'eaten'
by the edges.
If you run ‘$ make check’ on the source files of Gnuastro, you can
see this effect by comparing the ‘convolve_frequency.fits’ with
‘convolve_spatial.fits’ in the ‘./tests/’ directory. In the spatial
domain, by default, no assumption will be made about pixels outside of
the image or any blank pixels in the image. The problem explained above
will also occur on the sides of blank regions (see *note Blank
pixels::). The solution to this edge effect problem is only possible in
the spatial domain. For pixels near the edge, we have to abandon the
assumption that the sum of the kernel pixels is unity during the
convolution process(2). So taking $W$ as the sum of the kernel pixels
that overlapped with non-blank and in-image pixels, the equation in
*note Convolution process:: will become:
$$C_{x,y}= { \sum_{s=-a}^{a}\sum_{t=-b}^{b}K_{s,t}\times{}I_{x+s,y+t} \over W}.$$
In this manner, objects which are near the edges of the image or blank
pixels will also have the same brightness (within the image) before and
after convolution. This correction is applied by default in Convolve
when convolving in the spatial domain. To disable it, you can use the
‘--noedgecorrection’ option. In the frequency domain, there is no way
to avoid this loss of flux near the edges of the image, see *note Edges
in the frequency domain:: for an interpretation from the frequency
domain perspective.
Note that the edge effect discussed here is different from the one in
*note If convolving afterwards::. In making mock images we want to
simulate a real observation. In a real observation, the images of the
galaxies on the sides of the CCD are first blurred by the atmosphere and
instrument, then imaged. So light from the parts of a galaxy which are
immediately outside the CCD will affect the parts of the galaxy which
are covered by the CCD. Therefore in modeling the observation, we have
to convolve an image that is larger than the input image by exactly half
of the convolution kernel. We can hence conclude that this correction
for the edges is only useful when working on actual observed images
(where we do not have any more data on the edges) and not in modeling.
---------- Footnotes ----------
(1) Because we assumed the overlapping pixels outside the input image
have a value of zero.
(2) Of course the sum of the kernel pixels still have to be unity in
general.
File: gnuastro.info, Node: Frequency domain and Fourier operations, Next: Spatial vs. Frequency domain, Prev: Spatial domain convolution, Up: Convolve
6.3.2 Frequency domain and Fourier operations
---------------------------------------------
Getting a good grip on the frequency domain is usually not an easy job!
So we have decided to give the issue a complete review here.
Convolution in the frequency domain (see *note Convolution theorem::)
heavily relies on the concepts of Fourier transform (*note Fourier
transform::) and Fourier series (*note Fourier series::) so we will be
investigating these important operations first. It has become something
of a cliché for people to say that the Fourier series "is a way to
represent a (wave-like) function as the sum of simple sine waves" (from
Wikipedia). However, sines themselves are abstract functions, so this
statement really adds no extra layer of physical insight.
Before jumping head-first into the equations and proofs, we will
begin with a historical background to see how the importance of
frequencies actually roots in our ancient desire to see everything in
terms of circles. A short review of how the complex plane should be
interpreted is then given. Having paved the way with these two basics,
we define the Fourier series and subsequently the Fourier transform.
The final aim is to explain discrete Fourier transform, however some
very important concepts need to be solidified first: The Dirac comb,
convolution theorem and sampling theorem. So each of these topics are
explained in their own separate sub-sub-section before going on to the
discrete Fourier transform. Finally we revisit (after *note Edges in
the spatial domain::) the problem of convolution on the edges, but this
time in the frequency domain. Understanding the sampling theorem and
the discrete Fourier transform is very important in order to be able to
pull out valuable science from the discrete image pixels. Therefore we
have included the mathematical proofs and figures so you can have a
clear understanding of these very important concepts.
* Menu:
* Fourier series historical background:: Historical background.
* Circles and the complex plane:: Interpreting complex numbers.
* Fourier series:: Fourier Series definition.
* Fourier transform:: Fourier Transform definition.
* Dirac delta and comb:: Dirac delta and Dirac comb.
* Convolution theorem:: Derivation of Convolution theorem.
* Sampling theorem:: Sampling theorem (Nyquist frequency).
* Discrete Fourier transform:: Derivation and explanation of DFT.
* Fourier operations in two dimensions:: Extend to 2D images.
* Edges in the frequency domain:: Interpretation of edge effects.
File: gnuastro.info, Node: Fourier series historical background, Next: Circles and the complex plane, Prev: Frequency domain and Fourier operations, Up: Frequency domain and Fourier operations
6.3.2.1 Fourier series historical background
............................................
Ever since the ancient times, the circle has been (and still is) the
simplest shape for abstract comprehension. All you need is a center
point and a radius and you are done. All the points on a circle are at
a fixed distance from the center. However, the moment you try to
connect this elegantly simple and beautiful abstract construct (the
circle) with the real world (for example, compute its area or its
circumference), things become really hard (ideally, impossible) because
the irrational number $\pi$ gets involved.
The key to understanding the Fourier series (thus the Fourier
transform and finally the Discrete Fourier Transform) is our ancient
desire to express everything in terms of circles or the most
exceptionally simple and elegant abstract human construct. Most people
prefer to say the same thing in a more ahistorical manner: to break a
function into sines and cosines. As the term "ancient" in the previous
sentence implies, Jean-Baptiste Joseph Fourier (1768 - 1830 A.D.) was
not the first person to do this. The main reason we know this process
by his name today is that he came up with an ingenious method to find
the necessary coefficients (radius of) and frequencies ("speed" of
rotation on) the circles for any generic (integrable) function.
[image src="gnuastro-figures/epicycles.png" alt="Middle ages epicycles along with two demonstrations of breaking a generic function using epicycles." text="../gnuastro-figures//epicycles.png"