Book Image

IPython Interactive Computing and Visualization Cookbook

By : Cyrille Rossant
Book Image

IPython Interactive Computing and Visualization Cookbook

By: Cyrille Rossant

Overview of this book

Table of Contents (22 chapters)
IPython Interactive Computing and Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Segmenting an image


Image segmentation consists of partitioning an image into different regions that share certain characteristics. This is a fundamental task in computer vision, facial recognition, and medical imaging. For example, an image segmentation algorithm can automatically detect the contours of an organ in a medical image.

scikit-image provides several segmentation methods. In this recipe, we will demonstrate how to segment an image containing different objects.

How to do it...

  1. Let's import the packages:

    In [1]: import numpy as np
            import matplotlib.pyplot as plt
            from skimage.data import coins
            from skimage.filter import threshold_otsu
            from skimage.segmentation import clear_border
            from skimage.morphology import closing, square
            from skimage.measure import regionprops, label
            from skimage.color import lab2rgb
            %matplotlib inline
  2. We create a function that displays a grayscale image:

    In [2]: def show(img, cmap=None):
              ...