Comparing edge-based and region-based segmentation#

In this example, we will see how to segment objects from a background. We use the coins image from skimage.data, which shows several coins outlined against a darker background.

import numpy as np
import matplotlib.pyplot as plt

import skimage as ski

coins = ski.data.coins()
hist, hist_centers = ski.exposure.histogram(coins)

fig, axes = plt.subplots(1, 2, figsize=(8, 3))
axes[0].imshow(coins, cmap=plt.cm.gray)
axes[0].set_axis_off()
axes[1].plot(hist_centers, hist, lw=2)
axes[1].set_title('histogram of gray values')