Finding bright regions with ndimage#

How you can to find the brightest regions in an AIA image and count the approximate number of regions of interest using ndimage.

import matplotlib.pyplot as plt
from scipy import ndimage

from import AIA_193_IMAGE

We start with the sample data.

aiamap_mask =
aiamap =

First we make a mask, which tells us which regions are bright. We choose the criterion that the data should be at least 10% of the maximum value. Pixels with intensity values greater than this are included in the mask, while all other pixels are excluded.

mask = < aiamap.max() * 0.10

Mask is a bool array. It can be used to modify the original map object without modifying the data. Once this mask attribute is set, we can plot the image again.

aiamap_mask.mask = mask

fig = plt.figure()
ax = fig.add_subplot(projection=aiamap_mask)
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:07

Only the brightest pixels remain in the image. However, these areas are artificially broken up into small regions. We can solve this by applying some smoothing to the image data. Here we apply a 2D Gaussian smoothing function to the data.

The issue with the filtering is that it create pixels where the values are small (<100), so when we go on later to label this array, we get one large region which encompasses the entire array. If you want to see, just remove this line.

data2[data2 < 100] = 0

Now we will make a second sunpy map with this smoothed data.

aiamap2 =, aiamap.meta)

The function scipy.ndimage.label counts the number of contiguous regions in an image.

Finally, we plot the smoothed bright image data, along with the estimate of the number of distinct regions. We can see that approximately 6 distinct hot regions are present above the 10% of the maximum level.

fig = plt.figure()
ax = fig.add_subplot(projection=aiamap)
plt.figtext(0.3, 0.2, f'Number of regions = {n}', color='white')
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:07

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

Gallery generated by Sphinx-Gallery