# Automatic estimation of magnetic domain wall propagation

Here is an image analysis script I have recently written on my spare time for my friends at the national science research center (CNRS).

### The short story

We consider a magnetic nano-structure submitted to magnetic and/or electric field. Upon proper conditions, the magnetic state of the structure will evolve and switch from one polarity to the other. This can be observed using a specific magnetic imaging system.

Our objective is to perform an automatic image analysis to estimate the propagation speed of the polarity reversal mechanism (a magnetic domain wall).

### Looking at the images

Let’s first look at the raw images, as shown below. The reversal mechanism is the propagation of the black region from bottom to top of the image. The general quality is rather noisy, and the intensity not normalized. Also, the black box at the bottom should be removed.

### The idea

To analyse the propagation, we could imagine a shape analysis algorithm, but is there a simpler way ? Well, the propagation corresponds to a switching of pixels from white to black, so could we simply count those pixels ? Let’s try.

First, I’ll open all the images in a given folder and convert them to levels of gray. Then crop the images to keep only the interesting area, and finally perform an intensity rescaling to account for variations among the set.

```from skimage import io, color, exposure
from matplotlib import pyplot as plt
import pandas as pd

images_gray = []
print("The folder contains %s images" %len(images))
for i in range(len(images)):
img = color.rgb2gray(images[i]) #Convert to gray
img_crop = img[100:710,0:960] # Crop
img_crop = exposure.rescale_intensity(img_crop,(0,0.9)) #Intensity rescale for homogeneous images
images_gray.append(img_crop)
```

Next, I extract the histogram using skimage’s exposure module. The pixels are coded in a (256,1) array corresponding to each level of gray intensity : 0 for a white pixel, 255 for a black pixel.

I’ll calculate manually the cumulative distribution this could also be achieved using skimage.exposure.cumulative_distribution

```Count = pd.DataFrame() #Intensity count for all pixels, coded on 256 levels
X = pd.DataFrame() #Centers

for i in range(len(images_gray)):
c,x = exposure.histogram(images_gray[i])
Count[i] = c
X[i] = x

intensity = Count.cumsum()
#Could also use Count,x = exposure.cumulative_distribution(images_gray)```

The distribution is plotted for the initial and the final state, which clearly shows that the image is much darker at the final state. Now let’s plot the evolution of the intensity for each photo from inital to final state : The domain wall propagates rapidly in the first steps then reaches a plateau that corresponds to the filling of the last rectangle in the center.

Knowing the time interval between each picture and the size of the sample it is easy to estimate the propagation speed. Knowing that the size of the sample is 100 µm, I will also rescale the intensity from 0 to 100µm.

Finally, the average propagation speed is given by the slope of the linear fit (note the fit is performed for the 16 first points only). And we’re done ! We have automatically processed 23 images, analyzed their intensity to calculate the average propagation speed.

This site uses Akismet to reduce spam. Learn how your comment data is processed.