Core modules of this library.

Utility Functions

expand_dim_to_3[source]

expand_dim_to_3(arr)

parametric_ellipse[source]

parametric_ellipse(alpha, A, a, b)

elliplise[source]

elliplise(axes, angle, center=None, width=None, height=None)

class EllipticalSeparabilityFilter[source]

EllipticalSeparabilityFilter(axes_in, axes_out, angle)

EllipticalSeparabilityFilter.find_circles[source]

EllipticalSeparabilityFilter.find_circles(img, num_circles=None)

Usage Example

Given an image of persons face, we may want to detect the region of that persons eyes (I've hidden the definition of some plotting functions such as show and plot_images for readability).

img = cv.cvtColor(cv.imread('../images/face.jpeg'), cv.COLOR_BGR2RGB)
img = cv.resize(img, (192, 128))
show(img)

For such an image, it is useful to have a template filter that matches the size of the eye. Templates sizes can be determined by manual tuning or automated search algorithms. Below is an example of an appropriate template.

esf = EllipticalSeparabilityFilter(axes_in=(4,4), axes_out=(20,20),angle=0)
plot_images(esf.ellipse_templates())

Using this template we can caluclate a separability map from the image.

sepmap = esf(img)
show(sepmap)

Using the find_circles function, we can find a number of circles in the image.

points = esf.find_circles(img, num_circles=2)
print(points)

plt.imshow(sepmap.squeeze())
plt.scatter(*points.T, color='red', s=100) 
[[95 56]
 [72 52]]
<matplotlib.collections.PathCollection at 0x7f24472b5d60>

Other examples

img = cv.cvtColor(cv.imread('../images/eye.png'), cv.COLOR_BGR2RGB)
img = cv.resize(img, (192, 128))

esf = EllipticalSeparabilityFilter(axes_in=(4,4), axes_out=(20,20),angle=0)
sepmap = esf(img)
plot_images([img, *esf.ellipse_templates(), sepmap])

esf = EllipticalSeparabilityFilter(axes_in=(20,20), axes_out=(30,20),angle=0)
sepmap = esf(img)
plot_images([img, *esf.ellipse_templates(), sepmap])

esf = EllipticalSeparabilityFilter(axes_in=(10,10), axes_out=(40,20),angle=-5)
sepmap = esf(img)
plot_images([img, *esf.ellipse_templates(), sepmap])
img = cv.cvtColor(cv.imread('../images/football.jpg'), cv.COLOR_BGR2RGB)
img = cv.resize(img, (192, 128))

esf = EllipticalSeparabilityFilter(axes_in=(8,8), axes_out=(25,25),angle=0)
sepmap = esf(img)
plot_images([img, *esf.ellipse_templates(), sepmap])

esf = EllipticalSeparabilityFilter(axes_in=(3,3), axes_out=(40,40),angle=0)
sepmap = esf(img)
plot_images([img, *esf.ellipse_templates(), sepmap])