Automatically find the center of the speckle pattern and most intense rings


In [1]:
import skbeam.core.roi as roi

import numpy as np

import matplotlib.pyplot as plt
%matplotlib notebook

In [2]:
x = np.linspace(-5,5,200)
X,Y = np.meshgrid(x,x)
Z = 100*np.cos(np.sqrt(x**2 + Y**2))**2 + 50

In [3]:
center, image, radii = roi.auto_find_center_rings(Z, sigma=20, no_rings=5)
fig, ax = plt.subplots()
ax.scatter(center[0], center[1], s=50, c='red')
im = ax.imshow(image,  cmap="viridis")
cbar = fig.colorbar(im)



In [4]:
center


Out[4]:
(99, 99)

In [5]:
radii


Out[5]:
[40.548419895684823,
 77.451824437527122,
 121.06033211800042,
 83.846172104974556,
 80.984726733100459]

Two examples to demonstarte automatically find the center of the speckle pattern and most intense 4 rings

First image


In [6]:
duke_img = np.load("image_data/duke_img.npy" )

fig, ax = plt.subplots()
im = ax.imshow(duke_img, vmax=1e0, cmap="viridis");  
fig.colorbar(im)
plt.show()



In [7]:
center_a, image_a, radii_a = roi.auto_find_center_rings(duke_img, sigma=2, no_rings=4)
radii_a


/Users/sameera/mc/envs/py3k/lib/python3.4/site-packages/skimage/measure/fit.py:378: RuntimeWarning: invalid value encountered in true_divide
  A[0, :] = -(x - xc) / d
/Users/sameera/mc/envs/py3k/lib/python3.4/site-packages/skimage/measure/fit.py:379: RuntimeWarning: invalid value encountered in true_divide
  A[1, :] = -(y - yc) / d
Out[7]:
[50.755494324945069,
 38.369895534416862,
 33.041516344030768,
 27.483268525122753]

Plot the image with the center and the radii


In [8]:
fig, ax = plt.subplots()
plt.scatter(center_a[0], center_a[1], s=50, c='green')
ax.set_title("Center and 4 most intense rings")
ax.set_xlabel("pixels")
ax.set_ylabel("pixels")
im_a = ax.imshow(image_a, vmax=1e0, cmap="viridis");  
fig.colorbar(im_a)


Out[8]:
<matplotlib.colorbar.Colorbar at 0x110cbf240>

Second example


In [9]:
nipa_avg = np.load("image_data/nipa_avg.npy")

In [10]:
center_n, image_n, radii_n = roi.auto_find_center_rings(nipa_avg, sigma=20, no_rings=2)


/Users/sameera/mc/envs/py3k/lib/python3.4/site-packages/skimage/measure/fit.py:378: RuntimeWarning: invalid value encountered in true_divide
  A[0, :] = -(x - xc) / d
/Users/sameera/mc/envs/py3k/lib/python3.4/site-packages/skimage/measure/fit.py:379: RuntimeWarning: invalid value encountered in true_divide
  A[1, :] = -(y - yc) / d
/Users/sameera/mc/envs/py3k/lib/python3.4/site-packages/scipy/optimize/minpack.py:427: RuntimeWarning: gtol=0.000000 is too small, func(x) is orthogonal to the columns of
  the Jacobian to machine precision.
  warnings.warn(errors[info][0], RuntimeWarning)

In [11]:
fig, ax = plt.subplots()
ax.scatter(center_n[0], center_n[1], s=50, c='red')
im_n = ax.imshow(image_n,  cmap="viridis")
plt.colorbar(im_n)


Out[11]:
<matplotlib.colorbar.Colorbar at 0x10444dac8>

In [12]:
radii_n


Out[12]:
[122.60176841562823, 74.044818538677433]

In [13]:
center_n


Out[13]:
(-20, 162)

In [14]:
import skbeam
skbeam.__version__


Out[14]:
'0.0.10.post1.dev0+ga0b5c12'

In [ ]: