Scikit Image − Roberts Cross Operator



Roberts cross operator is a simple and efficient edge detection operator used in image processing and computer vision. It was one of the earliest edge detection methods and was proposed by Lawrence Roberts in 1963.

The primary purpose of the Roberts cross operator is to compute the gradient or change in intensity of an image at each pixel. Usually applied to grayscale images, this operator generates an output in which each pixel value represents the approximate absolute magnitude of the spatial gradient at the corresponding location in the input image.

The scikit-image (skimage) library, provides the below functions within its filter module to apply the Roberts' Cross operator to images.

The skimage.filters.roberts(image, mask=None) function

This function computes the edge magnitude using the Roberts' Cross operator on a 2D input image. It takes an input image and an optional mask and returns a 2-D array, which represents the Robert's edge map.

The skimage.filters.roberts_pos_diag(image, mask=None) function

This function specifically applies the Roberts' Cross operator with the positive diagonal kernel, and returns a 2-D array representing the Robert's edge map.

Following is the Kernel:

1   0
0  -1

The skimage.filters.roberts_neg_diag(image, mask=None) function

This function also finds cross edges in an image using the Roberts' Cross operator with a negative diagonal kernel. It returns a 2-D array representing the Robert's edge map.

Following is the Kernel:

0   1
-1   0

Example

The following example demonstrates how to use the Roberts filter to perform edge detection on a grayscale image using the filters.roberts() function −

import matplotlib.pyplot as plt
from skimage.filters import roberts
from skimage import io, color

# Load the input image and convert the image to grayscale 
image = color.rgb2gray(io.imread('Images/Lines_3.jpg'))

# Apply the Roberts filter 
filtered_image = roberts(image)

# Plot the original and filtered images
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
ax = axes.ravel()

# Display the Original Image
ax[0].imshow(image, cmap='gray')
ax[0].set_title('Original Image')
ax[0].axis('off')

# Display the Roberts Filter Result
ax[1].imshow(filtered_image, cmap='gray')
ax[1].axis('off')
ax[1].set_title('Roberts Filter Result')

plt.tight_layout()
plt.show()

Output

Robert Filter

Example

The following example demonstrates how to use the Roberts filter to perform edge detection on a grayscale image using the filters.roberts_pos_diag() and filter.roberts_neg_diag() functions −

import matplotlib.pyplot as plt
from skimage.filters import roberts_neg_diag, roberts_pos_diag
from skimage import io, color

# Load the input image
image = io.imread('Images/lines_3.jpg')

# Convert the image to grayscale for Roberts filtering
gray_image = color.rgb2gray(image)

# Apply the Roberts Negative Diagonal filter
filtered_image_neg_diag = roberts_neg_diag(gray_image)

# Apply the Roberts Positive Diagonal filter
filtered_image_pos_diag = roberts_pos_diag(gray_image)

# Plot the original, Roberts Negative Diagonal, and Roberts Positive Diagonal filtered images
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
ax = axes.ravel()

# Display the Original Image
ax[0].imshow(gray_image, cmap='gray')
ax[0].set_title('Original Image')
ax[0].axis('off')

# Display the Roberts Negative Diagonal Filter Result
ax[1].imshow(filtered_image_neg_diag, cmap='gray')
ax[1].set_title('Roberts Negative Diagonal Filter Result')
ax[1].axis('off')

# Display the Roberts Positive Diagonal Filter Result
ax[2].imshow(filtered_image_pos_diag, cmap='gray')
ax[2].set_title('Roberts Positive Diagonal Filter Result')
ax[2].axis('off')

plt.tight_layout()
plt.show()

Output

Robert Filter
Advertisements