
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image - Active Contour Model
The active contour model, also known as the snake model, is a widely used technique in image processing and computer vision. It was introduced by Michael Kass, Andrew Witkin, and Demetri Terzopoulos for contour extraction and object boundary detection.
This model operates by fitting open or closed splines to lines or edges present within an image. The process involves minimizing an energy function that combines information from both the image and the spline's shape, including its length and smoothness. The minimization is performed implicitly in the shape energy and explicitly in the image energy.
The scikit-image library offers the active_contour function within its segmentation submodule to apply the active contour model.
Using the skimage.segmentation.active_contour() function
The segmentation.active_contour() function is used for the active contour model. Active contours by fitting snakes to features of images, allowing for segmentation and boundary detection. This function supports both single and multichannel 2D images and provides flexibility for configuring the behavior of the snake.
Syntax
Following is the syntax of this function −
skimage.segmentation.active_contour(image, snake, alpha=0.01, beta=0.1, w_line=0, w_edge=1, gamma=0.01, max_px_move=1.0, max_num_iter=2500, convergence=0.1, *, boundary_condition='periodic')
Parameters
The function accepts the following parameters −
image: (N, M) or (N, M, 3) ndarray: This parameter represents the input image.
snake: (N, 2) ndarray : This parameter specifies the initial snake coordinates. For periodic boundary conditions, ensure that the endpoints are not duplicated.
alpha: float, optional : Snake length shape parameter. Higher values make the snake contract faster.
beta: float, optional : Snake smoothness shape parameter. Higher values result in a smoother snake.
w_line: float, optional : Controls attraction to brightness. Use negative values to attract the snake toward dark regions.
w_edge: float, optional : Controls attraction to edges. Use negative values to repel the snake from edges.
gamma: float, optional : Explicit time stepping parameter.
max_px_move: float, optional : Specifies the maximum pixel distance the snake can move per iteration.
max_num_iter: int, optional : Sets the maximum number of iterations to optimize the snake's shape.
convergence: float, optional : Convergence criteria.
boundary_condition: string, optional : Defines the boundary conditions for the contour. It can take one of the following values: 'periodic', 'free', 'fixed', 'free-fixed', or 'fixed-free'. 'periodic' attach the two ends of the snake, 'fixed' holds the end-points in place, and 'free' allows free movement of the ends. 'fixed' and 'free' can be combined by parsing 'fixed-free' or 'free-fixed'. Parsing 'fixed-fixed' or 'free-free' yields the same behavior as 'fixed' and 'free', respectively.
The function returns the optimized snake((N, 2) ndarray), which has the same shape as the input parameter.
Example
In the following two examples, the active contour model is used to segment the face of a person from the rest of an image by fitting a closed curve to the edges of the face using the active_contour() function.
import numpy as np import matplotlib.pyplot as plt from skimage.color import rgb2gray from skimage import io from skimage.filters import gaussian from skimage.segmentation import active_contour # Load the input image as a grayscale image img = io.imread('Images/boy.jpg', as_gray=True) # Create initial snake coordinates s = np.linspace(0, 2*np.pi, 400) r = 150 + 100*np.sin(s) c = 250 + 100*np.cos(s) init = np.array([r, c]).T # Apply the active contour model to segment the image snake = active_contour(gaussian(img, sigma=3, preserve_range=False), init, alpha=0.015, beta=10, gamma=0.001) # Create a plot to visualize the original image and the snake fig, ax = plt.subplots(figsize=(7, 7)) ax.imshow(img, cmap=plt.cm.gray) ax.plot(init[:, 1], init[:, 0], '--r', lw=3) ax.plot(snake[:, 1], snake[:, 0], '-b', lw=3) ax.set_xticks([]), ax.set_yticks([]) ax.axis([0, img.shape[1], img.shape[0], 0]) plt.show()
Output

Example
In this example, the active contour model is used to find the darkest curve between two fixed points while obeying smoothness considerations. It initializes a straight line between the two fixed points, (5, 136) and (424, 50), and ensures that the spline's endpoints remain fixed by specifying the boundary condition as boundary_condition='fixed'. Additionally, the algorithm is instructed to search for dark lines by assigning a negative value to w_line.
import numpy as np import matplotlib.pyplot as plt from skimage.color import rgb2gray from skimage import io from skimage.filters import gaussian from skimage.segmentation import active_contour # Load the input image img = io.imread('Images/hand writting.jpg', as_gray=True) # Create initial snake coordinates r = np.linspace(136, 50, 100) c = np.linspace(5, 424, 100) init = np.array([r, c]).T # Apply the active contour model to segment the text in the image snake = active_contour(gaussian(img, sigma=1, preserve_range=False), init, boundary_condition='fixed', alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1) # Create a plot to visualize the original image and the snake fig, ax = plt.subplots(figsize=(9, 5)) ax.imshow(img, cmap=plt.cm.gray) ax.plot(init[:, 1], init[:, 0], '--r', lw=3) # Initial snake in red ax.plot(snake[:, 1], snake[:, 0], '-b', lw=3) # Optimized snake in blue ax.set_xticks([]), ax.set_yticks([]) # Hide tick marks ax.axis([0, img.shape[1], img.shape[0], 0]) # Set axis limits # Show the plot plt.show()
Output
