Comprehensive image processing and computer vision library for Python with algorithms for filtering, morphology, segmentation, and feature detection
npx @tessl/cli install tessl/pypi-scikit-image@0.25.0A comprehensive Python library for image processing and computer vision. scikit-image provides a collection of algorithms for image processing including color space conversion, filtering, morphology, segmentation, feature detection, geometric transformations, and measurement operations. It serves as the foundational image processing library for the Python scientific ecosystem.
pip install scikit-imageimport skimageCommon submodule imports:
from skimage import io, filters, morphology, segmentation
from skimage.feature import canny, corner_harris
from skimage.transform import resize, rotate
from skimage.measure import label, regionpropsimport numpy as np
from skimage import io, filters, morphology, measure
# Load an image
image = io.imread('path/to/image.jpg')
# Convert to grayscale if needed
from skimage.color import rgb2gray
gray_image = rgb2gray(image)
# Apply Gaussian filter for noise reduction
smooth = filters.gaussian(gray_image, sigma=1.0)
# Edge detection
edges = filters.sobel(smooth)
# Morphological operations
cleaned = morphology.remove_small_objects(edges > 0.1, min_size=100)
# Label connected components
labeled = measure.label(cleaned)
props = measure.regionprops(labeled)
# Basic measurements
for prop in props:
print(f"Area: {prop.area}, Centroid: {prop.centroid}")
# Save processed image
io.imsave('processed_image.jpg', cleaned)scikit-image is organized into focused submodules, each targeting specific image processing domains:
This modular design enables selective imports and provides clear separation of concerns for different image processing workflows.
Convert between different color representations including RGB, HSV, LAB, XYZ and specialized spaces for histological imaging and color analysis.
def rgb2gray(rgb): ...
def rgb2hsv(rgb): ...
def rgb2lab(rgb, illuminant='D65', observer='2'): ...
def hsv2rgb(hsv): ...
def lab2rgb(lab, illuminant='D65', observer='2'): ...
def rgba2rgb(rgba, background=(1, 1, 1)): ...Apply filters for noise reduction, edge detection, sharpening, and enhancement. Includes Gaussian filters, edge detection operators, ridge filters, and thresholding methods.
def gaussian(image, sigma=1, **kwargs): ...
def sobel(image, mask=None, **kwargs): ...
def canny(image, sigma=1, low_threshold=None, **kwargs): ...
def threshold_otsu(image, nbins=256): ...
def median(image, disk=None, **kwargs): ...
def unsharp_mask(image, radius=1.0, amount=1.0, **kwargs): ...Perform morphological operations including erosion, dilation, opening, closing, and advanced operations with customizable structuring elements.
def erosion(image, footprint=None, **kwargs): ...
def dilation(image, footprint=None, **kwargs): ...
def opening(image, footprint=None, **kwargs): ...
def closing(image, footprint=None, **kwargs): ...
def skeletonize(image, method='lee'): ...
def remove_small_objects(ar, min_size=64, **kwargs): ...Transform images through rotation, scaling, warping, and coordinate system transformations. Includes support for various transformation models and image pyramids.
def resize(image, output_shape, **kwargs): ...
def rotate(image, angle, **kwargs): ...
def rescale(image, scale, **kwargs): ...
def warp(image, inverse_map, **kwargs): ...
class AffineTransform(matrix=None, **kwargs): ...
class ProjectiveTransform(matrix=None, **kwargs): ...Partition images into regions using watershed, region growing, active contours, and superpixel algorithms for object detection and analysis.
def watershed(image, markers=None, **kwargs): ...
def random_walker(data, labels, **kwargs): ...
def slic(image, n_segments=100, **kwargs): ...
def felzenszwalb(image, scale=1, **kwargs): ...
def chan_vese(image, **kwargs): ...
def active_contour(image, snake, **kwargs): ...Detect and describe image features including corners, edges, blobs, and keypoints. Includes modern feature descriptors like SIFT, ORB, and texture analysis methods.
def corner_harris(image, method='k', **kwargs): ...
def corner_peaks(image, **kwargs): ...
def blob_log(image, **kwargs): ...
def blob_dog(image, **kwargs): ...
class ORB(n_keypoints=500, **kwargs): ...
class SIFT(**kwargs): ...Measure geometric properties, analyze regions, compute image moments, and extract quantitative information from processed images.
def label(image, background=None, **kwargs): ...
def regionprops(label_image, intensity_image=None, **kwargs): ...
def find_contours(image, level=0.5, **kwargs): ...
def moments(image, order=3): ...
def centroid(image): ...
def perimeter(image, neighbourhood=4): ...Read and write images in various formats with support for image collections, metadata handling, and multi-frame images.
def imread(fname, **kwargs): ...
def imsave(fname, arr, **kwargs): ...
class ImageCollection(pattern, **kwargs): ...
def imread_collection(pattern, **kwargs): ...Restore degraded images through deconvolution, denoising, and inpainting algorithms for image quality improvement.
def denoise_tv_chambolle(image, weight=0.1, **kwargs): ...
def denoise_bilateral(image, **kwargs): ...
def denoise_wavelet(image, **kwargs): ...
def richardson_lucy(image, psf, num_iter=50, **kwargs): ...
def inpaint_biharmonic(image, mask, **kwargs): ...Adjust image intensity, perform histogram operations, and enhance image contrast for better visualization and analysis.
def rescale_intensity(image, in_range='image', out_range='dtype'): ...
def equalize_hist(image, nbins=256, mask=None): ...
def equalize_adapthist(image, kernel_size=None, **kwargs): ...
def adjust_gamma(image, gamma=1, gain=1): ...
def histogram(image, nbins=256, source_range='image', normalize=False): ...Create geometric shapes, draw on images, and generate synthetic test patterns for visualization and algorithm testing.
def line(r0, c0, r1, c1): ...
def circle_perimeter(r, c, radius, method='bresenham', shape=None): ...
def polygon(r, c, shape=None): ...
def disk(center, radius, shape=None): ...
def rectangle(start, end=None, extent=None, shape=None): ...
def set_color(image, coords, color, alpha=1): ...Access example images and synthetic datasets for testing algorithms and learning image processing techniques.
def camera(): ...
def coins(): ...
def astronaut(): ...
def binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2, **kwargs): ...
def checkerboard(): ...Convert between data types, generate noise, manipulate arrays, and access utility functions for image processing workflows.
def img_as_float(image, force_copy=False): ...
def img_as_uint(image, force_copy=False): ...
def img_as_ubyte(image, force_copy=False): ...
def random_noise(image, mode='gaussian', **kwargs): ...
def crop(ar, crop_width, **kwargs): ...
def montage(arr_in, **kwargs): ...from typing import Union, Optional, Tuple, List, Dict, Any
from numpy.typing import NDArray
import numpy as np
# Core image type
Image = NDArray[np.number]
# Common parameter types
Sigma = Union[float, Tuple[float, ...]]
Footprint = Optional[NDArray[np.bool_]]
Shape = Tuple[int, ...]
ColorTuple = Tuple[float, float, float]