You are on page 1of 6

SCIPY:

SciPy is a collection of mathematical algorithms and convenience functions built on the NumPy
extension of Python. It adds significant power to the interactive Python session by providing the user
with high-level commands and classes for manipulating and visualizing data. With SciPy, an
interactive Python session becomes a data-processing and system-prototyping environment rivalling
systems, such as MATLAB, IDL, Octave, R-Lab, and SciLab.
The additional benefit of basing SciPy on Python is that this also makes a powerful programming
language available for use in developing sophisticated programs and specialized applications.
Scientific applications using SciPy benefit from the development of additional modules in numerous
niches of the software landscape by developers across the world. Everything from parallel
programming to web and data-base subroutines and classes have been made available to the Python
programmer. All of this power is available in addition to the mathematical libraries in SciPy.
This tutorial will acquaint the first-time user of SciPy with some of its most important features. It
assumes that the user has already installed the SciPy package. Some general Python facility is also
assumed, such as could be acquired by working through the Python distribution’s Tutorial. For
further introductory help the user is directed to the NumPy documentation.
The benefit of using SciPy library in Python while making ML models is that it also makes a strong
programming language available for use in developing less complex programs and applications.
SciPy is organized into sub packages covering different scientific computing domains. These are
summarized in the following table:

Sub package Description


 cluster Clustering algorithms
 constants Physical and mathematical constants
 fftpack Fast Fourier Transform routines
 integrate Integration and ordinary differential equation solvers
 interpolate Interpolation and smoothing splines
 io Input and Output
 linalg Linear algebra
 ndimage N-dimensional image processing
 odr Orthogonal distance regression
 optimize Optimization and root-finding routines
 signal Signal processing
 sparse Sparse matrices and associated routines
 spatial Spatial data structures and algorithms
 special Special functions
 stats Statistical distributions and functions

Special Functions in SciPy:


Scipy.special module contains list of transcendental function, which are most often used in
mathematical operation across various disciplines. Here is the syntax for some of the most used
function from the scipy.special modules are:
 To calculate the area under a Gaussian curve, we use erf() function
scipy.special.erf()
 Syntax for Gamma function:
scipy.special.gamma()
 In order to calculate the log of Gamma, we use the following syntax:
scipy.special.gammaln()
 Elliptic Function
scipy.special.eppilj()

Image Processing in SciPy


The module for Image processing in SciPy is known as scipy.ndimage. The routines offered in this
modules are capable of application like geometrical transformation of images, including changes in
resolution, orientation, shape, etc; Image filtering using Gaussian, Weiner, Median, and other such
filters;  erosion, dilation, opening, closing of images can also be done using this module. 

SciPy Spatial

The scipy.spatial package can calculate Triangulation, Voronoi Diagram and Convex Hulls of a set
of points,by leveraging the Qhull library. Likewise, it contains KDTree implementations for
nearest-neighbour point queries and utilities for distance computations in various metrics.

 Convex Hulls:

In mathematics, the convex hull or convex envelope of a set of points X in Euclidean plan or in
a Euclidean space. It is the smallest convex set that contains X.

For example:
from scipy.spatial import ConvexHull  
import matplotlib.pyplot as plt  
points = np.random.rand(10, 2) 
hull = ConvexHull(points)  
plt.plot(points[:,0], points[:,1], 'o')  
for simplex in hull.simplices:  
plt.plot(points[simplex,0], points[simplex,1], 'k-')  
plt.show()    

Output: (convex hull)

Imutils:

A series of convenience functions to make basic image processing functions such as translation,
rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV
and both Python 2.7 and Python 3.

 Translation is the shifting of an image in either the x or y direction. To translate an image in


OpenCV you would need to supply the (x, y)-shift, denoted as (tx, ty) to construct the
translation matrix M:

We apply the cv2.warpAffine function.
For example:
 translate the image x=25 pixels to the right and y=75 pixels up
translated = imutils.translate(workspace, 25, -75)

 Rotating an image in OpenCV is accomplished by making a call


to cv2.getRotationMatrix2D and cv2.warpAffine. Further care has to be taken to supply
the (x, y)-coordinate of the point the image is to be rotated about.
For example:
for angle in xrange(0, 360, 90):
 rotate the image and display it
rotated = imutils.rotate(bridge, angle=angle)
cv2.imshow("Angle=%d" % (angle), rotated)

 Resizing an image in OpenCV is accomplished by calling the cv2.resize function. However,


special care needs to be taken to ensure that the aspect ratio is maintained.
This resize function of imutils maintains the aspect ratio and provides the keyword
arguments width and height
For example:
 loop over varying widths to resize the image to
for width in (400, 300, 200, 100):
 resize the image and display it
resized = imutils.resize(workspace, width=width)
cv2.imshow("Width=%dpx" % (width), resized)

Faceutils:
It is used to extract the facial landmark from the image of the subject. There are a variety of facial
landmark detectors, but all methods essentially try to localize and label the following facial regions:

 Mouth
 Right eyebrow
 Left eyebrow
 Right eye
 Left eye
 Nose
 Jaw
This method starts by using:
 A training set of labelled facial landmarks on an image. These images are manually labelled,
specifying specific (x, y)-coordinates of regions surrounding each facial structure.
 Priors, of more specifically, the probability on distance between pairs of input pixels.

Given this training data, an ensemble of regression trees is trained to estimate the facial landmark
positions directly from the pixel intensities themselves (i.e., no “feature extraction” is taking place).

The end result is a facial landmark detector that can be used to detect facial landmarks in real-
time with high quality predictions.
FACIAL LANDMARKS ON THE SUBJECT FACE
Pygame:
Pygame is a cross-platform set of Python modules designed for writing video games. It
includes computer graphics and sound libraries designed to be used with the
Python programming language.
Pygame uses the Simple DirectMedia Layer (SDL) library, with the intention of
allowing real-time computer game development without the low-level mechanics of the C
programming language and its derivatives. This is based on the assumption that the
most expensive functions inside games can be abstracted from the game logic, making it
possible to use a high-level programming language, such as Python, to structure the game.
Pygame version2 was planned as "pygame reloaded" in 2009, but development and
maintenance of pygame completely stopped until the end of 2016 with version 1.9.1. 
 Pygame commands
 import pygame – This is of course needed to access the PyGame
framework.

 pygame.init() – This initializes all the modules required for PyGame.

 pygame.display.set_mode((width, height)) – This will launch a


window of the desired size. The return value is a Surface object which is
the object you will perform graphical operations on.

 pygame.event.get() – This empties the event queue. If you do not call


this, the windows messages will start to pile up and your game will
become unresponsive in the opinion of the operating system.
 pygame.QUIT – This is the event type that is fired when you click on
the close button in the corner of the window.

You might also like