Examples

Edge operators

# -*- coding: utf-8 -*-
"""
==============
Edge operators
==============
Edge operators are used in image processing within edge detection algorithms.
They are discrete differentiation operators, computing an approximation of the
gradient of the image intensity function.
"""
import numpy as np
import matplotlib.pyplot as plt

from skipp import filters
from skimage.data import camera
from skimage.util import compare_images


image = camera().astype(np.float32)
edge_prewitt = filters.prewitt(image)
edge_sobel = filters.sobel(image)

fig, axes = plt.subplots(ncols=2, sharex=True, sharey=True,
                         figsize=(8, 4))

axes[0].imshow(edge_prewitt, cmap=plt.cm.gray)
axes[0].set_title('Prewitt Edge Detection')

axes[1].imshow(edge_sobel, cmap=plt.cm.gray)
axes[1].set_title('Sobel Edge Detection')

for ax in axes:
    ax.axis('off')

plt.tight_layout()
plt.show()
_images/plot_edge_filters_example_output.png

original python script

Using geometric transformations

"""
===============================
Using geometric transformations
===============================

This example illustrates use of geometric transformations in the context of
image processing.
"""

import math
import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skipp import transform

######################################################################
# Basics
# ======
#
# Affine geometric transformation is supported.
#
# Geometric transformations can either be created using the explicit
# parameters (e.g. scale, shear, rotation and translation) or the
# transformation matrix.
#
# Create a transformation using explicit parameters:

tform = transform.AffineTransform(scale=1, rotation=math.pi/2,
                                  translation=(0, 1))
print(tform.params)

######################################################################
# Alternatively, define through a transformation matrix:
# itself:

matrix = tform.params.copy()
matrix[1, 2] = 2
tform2 = transform.AffineTransform(matrix)

######################################################################
# Image warping
# =============
#
# Geometric transformations can also be used to warp images:

text = data.text()

tform = transform.AffineTransform(scale=1, rotation=math.pi/4,
                                  translation=(text.shape[0]/2, -100))

rotated = transform.warp(text, tform)

fig, ax = plt.subplots(nrows=2)

ax[0].imshow(text, cmap=plt.cm.gray)
ax[1].imshow(rotated, cmap=plt.cm.gray)

for a in ax:
    a.axis('off')

plt.tight_layout()
plt.show()
_images/plot_geometric_example_output.png

original python script