SciPy - face() Method



The SciPy face() method is used to get the images of a racoon. This method also applied to various application such as edge detection, filtering and transformation.

Syntax

Following is the syntax of the SciPy method −

face()

Parameters

This method does not take any parameter.

Return value

This method returns the image of a racoon face.

Example 1

Following is the basic example of SciPy face() method illustrates the face of racoon.

import matplotlib.pyplot as plt
from scipy.misc import face

# load the face image
image = face()

# display the image using matplotlib
plt.imshow(image)
plt.title('Face Image')
plt.axis('off')
plt.show()

Output

The above code produces the following output −

scipy_face_method_one

Example 2

Here, we convert the original(face) image into gray-scale using the weighted sum of RGB components. Thus, it displayed both images in parallel mode.

import matplotlib.pyplot as plt
from scipy.misc import face
import numpy as np

# load the face image
image = face()

# convert the image to grayscale
gray_image = np.dot(image[..., :3], [0.299, 0.587, 0.114])

# display the original and grayscale images
fig, axes = plt.subplots(1, 2, figsize=(12, 6))
axes[0].imshow(image)
axes[0].set_title('Original Image')
axes[0].axis('off')

axes[1].imshow(gray_image, cmap='gray')
axes[1].set_title('Grayscale Image')
axes[1].axis('off')

plt.show()

Output

The above code produces the following output −

scipy_face_method_two

Example 3

To obtain the edge detection image, it uses two axes(0 and 1) to determine all its behaviors and in the same way, it applies a canny filter(cmap = 'gray') to another axis and shows the result side by side.

import matplotlib.pyplot as plt
from scipy.misc import face
from skimage.color import rgb2gray
from skimage.feature import canny

# load the face image
image = face()

# convert the image to grayscale
gray_image = rgb2gray(image)

# apply the Canny edge detector
edges = canny(gray_image, sigma=2)

# display the original and edge-detected images
fig, axes = plt.subplots(1, 2, figsize=(12, 6))

# first axes
axes[0].imshow(image)
axes[0].set_title('Original Image')
axes[0].axis('off')

# Second axes
axes[1].imshow(edges, cmap='gray')
axes[1].set_title('Edge Detection using Canny Filter')
axes[1].axis('off')

plt.show()

Output

The above code produces the following output −

scipy_face_method_three
scipy_reference.htm
Advertisements