Coalignment using Template Matching#

A common approach to coaligning a time series of images is to take a representative template that contains the features you are interested in, and match that to your images. The location of the best match tells you where the template is in your image. The images are then shifted to the location of the best match. This aligns your images to the position of the features in your representative template.

This example demonstrates how to coalign maps in a MapSequence using the mapsequence_coalign_by_match_template() function. The implementation of this functionality requires the installation of the image processing library scikit-image.

import matplotlib.pyplot as plt
from import Map

from sunkit_image import coalignment

Create a MapSequence using sample data.

mc = Map(

Plot an animation of the MapSequence that we can compare with the coaligned MapSequence.

anim = mc.plot()
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:07

To coalign the MapSequence, apply the mapsequence_coalign_by_match_template() function.

coaligned = coalignment.mapsequence_coalign_by_match_template(mc)

This returns a new MapSequence coaligned to a template extracted from the center of the first map in the MapSequence, with the dimensions clipped as required.

For a full list of options and functionality of the coalignment algorithm, see mapsequence_coalign_by_match_template.

Now, let’s plot an animation of the coaligned MapSequence to compare with the original.

anim_coalign = coaligned.plot()
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:07

If you just want to calculate the shifts required to compensate for solar rotation relative to the first map in the MapSequence without applying the shifts, use calculate_match_template_shift():

shifts = coalignment.calculate_match_template_shift(mc)

This is the function used to calculate the shifts in mapsequence_coalign_by_match_template(). The shifts calculated here can be passed directly to the coalignment function.

coaligned_shifts = coalignment.mapsequence_coalign_by_match_template(mc, shift=shifts)

anim_coaligned_shifts = coaligned_shifts.plot()
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:07

Total running time of the script: (0 minutes 12.662 seconds)

Gallery generated by Sphinx-Gallery