Skip to main content

Feature detection with scikit-image

Feature detection and analysis

In this project I will be using the powerful image analysis package skimage to segment objects in an image of interest and measure properties of detected features.

I will be using an example, a brightness image at the continuum around 500 nm of an active region imaged by Sunrise balloon observatory through the spectropolarimeter IMAX. The aim is to find the small-scale magnetic elements and inspect their feature properties.

In [1]:
## loading libraries
import matplotlib.pyplot as plt
import numpy as np
import pyfits
from numpy import flipud
In [2]:
## loading data
p = '/home/fatima/Desktop/project_2/alignment/'
imax = np.flipud(pyfits.getdata(p+'imax_007.fits'))   # loading the IMaX brightness image
B = np.flipud(pyfits.getdata(p+'B_los_007.fits'))     # loading the magnetic field map
fig = plt.figure(figsize=(15,10))
ax1 = fig.add_subplot(1,2,1)
ax1.imshow(imax, cmap='gray',vmin=imax.mean()-2*imax.std(),vmax = imax.mean()+2*imax.std())
ax2 = fig.add_subplot(1,2,2)
ax2.imshow(B, cmap='gray',vmin=B.mean()-2*B.std(),vmax = B.mean()+2*B.std())
Out[2]:
<matplotlib.image.AxesImage at 0x7fc0aaae9d10>

A pixel by pixel scatter plot of the brightness vs magnetic field allows me to identify the region where the magnetic elements belong to. They are all the pixels with a magnetic field above 600 G. I will make a contour plot enclosing all pixels having this threshold.

In [3]:
x = np.arange(imax.shape[1])
y = np.arange(imax.shape[0])
x,y = np.meshgrid(x,y)        #making a meshgrid with the dimensions of imax image
In [4]:
fig = plt.figure(figsize=(15,10))
ax1 = fig.add_subplot(1,2,1)
ax1.imshow(imax, cmap='gray',vmin=imax.mean()-2*imax.std(),vmax = imax.mean()+2*imax.std())
ax1.contour(x,y,np.abs(B),[700],colors='yellow')
ax2 = fig.add_subplot(1,2,2)
ax2.imshow(np.abs(B), cmap='gray',vmin=B.mean()-2*B.std(),vmax = B.mean()+2*B.std())
ax2.contour(x,y,np.abs(B),[700], colors='yellow')
Out[4]:
<matplotlib.contour.QuadContourSet at 0x7fc0aa9b60d0>