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):
connie_image.png

Cutout of 1/8th of a CCD showing nice events:
CONNIE.png

Cutout in FITS format

A CS82 cutout on a system containing gravitational arcs

A complete CS82 tile containing a gravitational arc system:

tile1.png

Cutout of a selected gravitational arc system:

cutout.png

Postage Stamp of the selected arc:

postage-stamp.png

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

Topic attachments
I Attachment Action Size Date Who Comment
PNGpng CONNIE.png manage 449.5 K 2015-06-28 - 06:36 AnaFoguel  
Unknown file formattex appA_imageprocessing.tex manage 38.9 K 2015-06-03 - 02:46 MartinMakler Appendix A source
Unknown file formatfits arco.fits manage 1338.8 K 2015-10-27 - 03:41 AliceCandeias  
Unknown file formatfits connie_cutout.fits manage 3912.2 K 2015-06-28 - 06:35 AnaFoguel  
PNGpng connie_image.png manage 522.3 K 2015-07-02 - 10:51 AnaFoguel  
PNGpng cut.png manage 619.9 K 2017-10-04 - 19:20 IruataMartins 1000x1000 pixels cutout from CS82, centered at RA/DEC (10.287544, -0.73030181)
PNGpng cutout.png manage 45.0 K 2015-09-13 - 08:19 AliceCandeias  
PNGpng ds9-cut_seg.png manage 52.5 K 2017-10-09 - 20:37 IruataMartins ds9 running on a SEGMENTATION output from sextractor
PNGpng ds9_blue_final.png manage 319.4 K 2017-10-15 - 19:32 IruataMartins  
PNGpng ds9_blue_move1.png manage 319.5 K 2017-10-15 - 19:32 IruataMartins  
PNGpng ds9_blue_move2.png manage 319.9 K 2017-10-15 - 19:32 IruataMartins  
PNGpng ds9_choose_panda.png manage 832.0 K 2017-10-15 - 19:32 IruataMartins  
PNGpng ds9_edit_region.png manage 890.8 K 2017-10-15 - 19:32 IruataMartins  
PNGpng ds9_marked_ellipse.png manage 315.4 K 2017-10-15 - 19:32 IruataMartins  
PNGpng ds9_marked_panda.png manage 313.6 K 2017-10-15 - 19:33 IruataMartins  
PNGpng ds9_panda0.png manage 323.8 K 2017-10-15 - 19:33 IruataMartins  
PNGpng ds9_panda1.png manage 339.8 K 2017-10-15 - 19:33 IruataMartins  
PNGpng ds9_panda_final.png manage 314.2 K 2017-10-15 - 19:33 IruataMartins  
PNGpng ds9_zoom.png manage 866.9 K 2017-10-15 - 19:33 IruataMartins  
PDFpdf finder_segment.pdf manage 505.8 K 2016-07-11 - 17:36 MartinMakler Procedure for segmenting the image with “finder.py”
PNGpng postage-stamp.png manage 1.7 K 2015-09-13 - 08:15 AliceCandeias  
Unknown file formatfits postage_fits.fits manage 14.1 K 2015-09-13 - 08:52 AliceCandeias  
PNGpng ps-116.png manage 1.9 K 2017-10-11 - 13:32 IruataMartins Postage stamp for object 116 in cut_seg.fits
PNGpng ps-cutoutinshapes.png manage 37.3 K 2017-10-15 - 19:41 IruataMartins  
PDFpdf thesis.pdf manage 14777.2 K 2015-06-03 - 02:46 MartinMakler Carlos Brandt's MSc thesis
PNGtiff tile.tiff manage 280.7 K 2015-09-13 - 08:15 AliceCandeias  
PNGpng tile1.png manage 215.5 K 2015-09-13 - 08:28 AliceCandeias  
Topic revision: r29 - 2017-10-15 - IruataMartins
 
No permission to view TWiki.TopMenuSkinTopBar
Online users: %VISITORS{format="$wikiusername" sep="$n" max="unlimited"}%