Examples of Basic Image Processing Tasks
The image processing exercise to be described here below comprises the search for specific objects/events inside scientific images. On one side we have images from the
CS82 project, on the other side images from the
CONNIExperiment. The nature of the events that generate the "objects" on each instrument are clearly different, nevertheless the processing is a search for patterns.
Carlos->Alice: The CS82 images will be handled by Alice. The objects of interest here are the gravitational arcs.
Carlos->Ana: The CONNIE images will be handled by Ana. The neutrino events are of interest here.
The software used for the processing and data handle can be found at
https://github.com/chbrandt/bit. It is a python library product of exercises like this one. From the library/software point of view, the objective here is to get an update, grow in functionality and improve its usability. The set of software in use, important or just useful for our work is further described at
the Software Stack page.
Technical note on image processing tools (in python)
Use as a starting point Carlo's thesis. Several procedures, including their results on an example image are found on
Appendix A (latex source here)
Data sample
Two image examples:
A single processed CCD from the CONNIE experiment:
A complete image from HDU 1 (containing both readings):
Cutout of 1/8th of a CCD showing nice events:
Cutout in FITS format
A CS82 cutout on a system containing gravitational arcs
A complete CS82 tile containing a gravitational arc system:
Cutout of a selected gravitational arc system:
Postage Stamp of the selected arc:
FITS for the cutout and for the postage stamp
CUTOUT
POSTAGE STAMP
Processing steps
Basically, we can split such kind of image processing
A pedagogical description of some basic image processing tasks can be found on Carlos Brandt's MSc thesis
here (see Appendix A)
Short description of tools on Carlo's repository that are not described in the document above:
- BIT library is summarized at page BitLib
Reading the image with pyfits
Creating a cutout from a FITS image
To create a
1000x1000
pixels image centered in a specific
$RA/$DEC
coordinate, we use SLTools' imcp:
$SLTOOLS/bin/imcp.py $ORIGINAL --coord-degrees -s 1000,1000 -- $RA $DEC
Unit: deg/px
Output image: cut.fits
By default, the output image is
cut.fits
.
To produce a png from out FITS cut, we use
trilogy:
shell% python trilogy.py cut.fits
and accept the default parameters. The output png is
cut.png
and looks like this:
Creating postage stamps (PS) from cutouts
Segmenting objects with SExtractor
Segment a FITS image into
OBJECTS and
SEGMENTATION (all pixels of the same object have the same intensity) files using the CS82 preset configuration:
shell% $SLTOOLS/bin/sextractor.py -q --preset=CS82 --segment cut.fits
Output files
CATALOG: cut_cat.fit
OBJECTS: cut_obj.fits
SEGMENT: cut_seg.fits
Open the resulting
cut_seg.fits
with
ds9
and find the desired object by pointing the mouse over it. The object's pixels all have the same intensity, equal to its identification number (
116 highlighted in red in the image below):
shell% ds9 cut_seg.fits
Creating a PS from SExtractor's OBJECTS and SEGMENTATION outputs
Create a
postage stamp for the object with id
116 from the OBJECTS and SEGMENTATION images:
shell% $SLTOOLS/bin/segobj2pstamp.py cut_obj.fits cut_seg.fits 116
Output file: ps-116.fits
Convert the resulting PS in a png image with Astromatic's
STIFF and
ImageMagick's convert:
shell% stiff -d >stiff.conf && stiff ps-116.fits -c stiff.conf
----- STIFF 2.4.0 started on 2017-10-11 at 10:30:24 with 4 threads
> BigTIFF support is: ON (libTIFF V4.0)
----- Inputs:
ps-116.fits: "S82_p9m" 49x46 32 bits (floats)
Background level: 0 Min level: -0.00280293 Max level: 2.80012
----- Output:
stiff.tif: 49x46 8 bits (integers) gamma: x1.00 compression: LZW
> All done (in 0.0 s: 8012.7 lines/s , 0.4 Mpixel/s)
shell% convert stiff.tif ps-116.png
Creating a PS using cutout in shapes
Open
cut.fits in ds9 and choose panda as the current region type:
Change the type of edition to region:
Zoom the image to help us mark a region:
Left-click near the center of the image to see a green target-like figure:
Left-click the target-like figure to show its sizing controls:
Click and drag a vertex of the square outside the circle to increase the region size. Click inside the square to move the region around.
Mark the region to be like this:
Click the little green square control at the bigger circle border angle 0 and drag it to the left
all the way to the control at angle 180.
The final result for the first move should be similtar to:
Repeat the process with the red bar in order to get this final region:
With the panda region marked and ds9 open, run
panda2arcellipse from gbclib:
shell% PYTHONPATH=$PYTHONPATH:$GBCLIB/pipelines
shell% $GBCLIB/applications/panda2arcellipse.py
Ds9 now shows an ellipse -- described in the
tmp.reg region file -- inside our panda region:
Run gbclib's
cut_polygon to extract the region inside the ellipse to a new FITS image:
shell% $GBCLIB/applications/cut_polygon.py
The FITS image and its region are respectively stored in
out.fits and
out.reg. Zoomed 4 times in ds9 they look like:
Create PS by identifying pixels above the background
Creation of Postage-Stamps "by hand" (no SExtractor):
- Start from a cutout, containing one or more contiguous objects, and a significant fraction of backgroung
- Plot the histogram of the pixel counts. Fit the "first bump" by a Gaussian, determining its centroid and FWHM/sigma
- Define a threshold as X times sigma (where X is in the range 3 - 5). Remove all pixels below threshold
- Apply connectivity operator do define the non-contiguous regions and separate into objects
Merging stamps
- Merge fragments of the same object (arcs may be separated in more than one image)
Image filtering
In the
bitlib
library, the
image
package has one module with several types of filtering:
filtering
(mean, median, gaussian, directional). Examples are given at
ImageFilteringExamples
Image rescaling
In the
bitlib
library, the
image
package has two modules with several types of rescaling:
image
(normalization, conversion to integer, inversion) and
rescaling
(hyperbolic tangent, clipping, and histogram equalization). Examples are given at
BasicProcessingSteps
Image statistic
ImageStatisticExamples
Image segmentation
In the
bitlib
library, the
image
package has one module with several types of segmentation:
segmentation
(seeds, threshold, region growth). Examples are given at
ImageSegmentationExamples
--
MartinMakler - 2015-06-03