Spot detection

Here is an example for spot detection in scopyon.analysis. This module requires scikit-image (https://scikit-image.org/).


In [1]:
import scopyon


/home/kaizu/.local/share/virtualenvs/python-eSbFG-Wg/lib/python3.7/site-packages/xarray/core/merge.py:18: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version
  PANDAS_TYPES = (pd.Series, pd.DataFrame, pd.Panel)
/home/kaizu/.local/share/virtualenvs/python-eSbFG-Wg/lib/python3.7/site-packages/xarray/core/dataarray.py:1829: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version
  'DataArray', pd.Series, pd.DataFrame, pd.Panel]:

In [2]:
config = scopyon.DefaultConfiguration()
config.default.detector.exposure_time = 33.0e-3
pixel_length = config.default.detector.pixel_length / config.default.magnification
L_2 = config.default.detector.image_size[0] * pixel_length * 0.5

In [3]:
import numpy.random
rng = numpy.random.RandomState(123)
N = 100
inputs = rng.uniform(-L_2, +L_2, size=(N, 2))

In [4]:
img, infodict = scopyon.form_image(inputs, config=config, rng=rng, full_output=True)

Detect spots in the given image. See also http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.blob_log for details. The default ROI size is 12x12.


In [5]:
spots = scopyon.analysis.spot_detection(
        img.as_array(), min_sigma=1, max_sigma=4, threshold=50.0, overlap=0.5)


/home/kaizu/.local/share/virtualenvs/python-eSbFG-Wg/lib/python3.7/site-packages/scopyon/analysis/spot_detection.py:81: RuntimeWarning: overflow encountered in exp
  a1 * numpy.exp(-((x - a2) ** 2 + (y - a3) ** 2) / a4))
/home/kaizu/.local/share/virtualenvs/python-eSbFG-Wg/lib/python3.7/site-packages/scopyon/analysis/spot_detection.py:81: RuntimeWarning: overflow encountered in multiply
  a1 * numpy.exp(-((x - a2) ** 2 + (y - a3) ** 2) / a4))

Overlay ROIs detected. Red shows spots detected, and green does true spots.


In [6]:
r = 6
shapes = [dict(x=data[2], y=data[3], sigma=r, color='green')
        for data in infodict['true_data'].values()]
shapes += [dict(x=spot[0], y=spot[1], sigma=r, color='red')
        for spot in spots]
img.show(shapes=shapes)