SciPy - ascent() Method



The SciPy ascent() method is used to get the 8-bit grayscale derieved image(512*512) which are uses for demos. This method allows user to experiment with image processing technique and apply the multiple filters and transformations.

Syntax

Following is the syntax of the SciPy ascent() method −

ascent()

Parameters

This method doesn't accept any parameter.

Return value

This method returns a 2D numpy array that shows the grayscale image.

Example 1

Following is the SciPy ascent() method that display the pre-existing ascent image.

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

# load the ascent image
image = ascent()

# display the image using matplotlib
plt.imshow(image, cmap='gray')
plt.title('Ascent Image')
plt.axis('off')
plt.show()

Output

The above code produces the following output −

scipy_ascent_method_one

Example 2

Below the example differentiate between original ascent image and gausian filtered image.

import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
from scipy.misc import ascent

# load the ascent image
image = ascent()

# apply a Gaussian filter to the image
filtered_image = gaussian_filter(image, sigma=3)

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

axes[1].imshow(filtered_image, cmap='gray')
axes[1].set_title('Gaussian Filtered Image')
axes[1].axis('off')

plt.show()

Output

The above code produces the following output −

scipy_ascent_method_two

Example 3

This method illustrates how to perform edge detection on original ascent image using sobel filter. This filter apply separately among the x and y axes which results as edge detected image alongside with original image.

import matplotlib.pyplot as plt
from scipy.ndimage import sobel
from scipy.misc import ascent

# load the ascent image
image = ascent()

# apply the Sobel filter to detect edges
sobel_x = sobel(image, axis=0)
sobel_y = sobel(image, axis=1)
edges = sobel_x + sobel_y

# Display the original image and the edge-detected image
fig, axes = plt.subplots(1, 2, figsize=(12, 6))
axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].axis('off')

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

plt.show()

Output

The above code produces the following output −

scipy_ascent_method_three
scipy_reference.htm
Advertisements