Skip to main content
scikit-image A collection of algorithms for image processing in Python. Built on NumPy, SciPy, and Cython. It focuses on scientific image analysis including segmentation, geometric transformations, color space manipulation, analysis, and filtering.
跳到安装 Skills Marketplace 发现并探索由社区构建的 Agent Skills
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tondevrel/scientific-agent-skills --skill scikit-image命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
下载 Zip 下载中... 同仓库更多 Skills Atomic Simulation Environment - a set of tools for setting up, manipulating, running, visualizing, and analyzing atomistic simulations. Acts as a universal interface between Python and numerous quantum chemical and molecular dynamics codes. Use for building atomic structures, geometry optimization, molecular dynamics simulations, transition state searches (NEB), file format conversion (CIF, XYZ, POSCAR, PDB), electronic property calculations (DOS, band structures), and automating simulation workflows with DFT/MD codes like VASP, GPAW, Quantum ESPRESSO, LAMMPS.
The core library for Astronomy and Astrophysics in Python. Provides data structures for coordinates, time, units, FITS files, and cosmological models. Essential for observational data reduction and theoretical astrophysics. Use when working with astronomical coordinates (RA/Dec), physical units, FITS files, time scales, WCS, cosmology, or astronomical tables.
A Python package useful for chemistry (mainly physical/analytical/inorganic chemistry). Features include balancing chemical reactions, chemical kinetics (ODE integration), chemical equilibria, ionic strength calculations, and unit handling. Use when working with chemical equations, reaction balancing, kinetic modeling, equilibrium calculations, speciation, pH calculations, ionic strength, activity coefficients, or chemical formula parsing.
name scikit-image description A collection of algorithms for image processing in Python. Built on NumPy, SciPy, and Cython. It focuses on scientific image analysis including segmentation, geometric transformations, color space manipulation, analysis, and filtering. version 0.22 license BSD-3-Clause
scikit-image - Scientific Image Processing
scikit-image treats images as NumPy arrays. It provides a comprehensive suite of algorithms for filtering, feature detection, and object measurement, making it the standard for research-grade image analysis.
When to Use
Preprocessing scientific images (noise reduction, contrast enhancement).
Image segmentation (separating cells, particles, or regions of interest).
Feature extraction (detecting edges, corners, blobs, or textures).
Geometric transformations (rescaling, rotating, warping).
Morphological operations (thinning, skeletonization, hole filling).
Measuring object properties (area, perimeter, eccentricity).
Restoring degraded images (deconvolution, inpainting).
Reference Documentation
Official docs : https://scikit-image.org/
User Guide : https://scikit-image.org/docs/stable/user_guide.html
Search patterns : skimage.filters, skimage.segmentation, ,
skimage.feature
skimage.morphology
Core Principles
Images are NumPy Arrays A grayscale image is a 2D array (M, N). A color image is a 3D array (M, N, 3). A multichannel 3D volume is (P, M, N, C).
Coordinate System The origin (0, 0) is at the top-left corner. Coordinates are always represented as (row, column).
Data Types and Ranges scikit-image handles various dtypes with specific ranges:
uint8: 0 to 255
uint16: 0 to 65535
float: -1 to 1 or 0 to 1
Quick Reference
Installation
Standard Imports import numpy as np
import matplotlib.pyplot as plt
from skimage import io, filters, segmentation, feature, measure, morphology, color, util
Basic Pattern - Load and Filter from skimage import io, filters, color
image = io.imread('data.png' )
gray_image = color.rgb2gray(image)
blurred = filters.gaussian(gray_image, sigma=2.0 )
io.imshow(blurred)
io.show()
Critical Rules
✅ DO
Use utility functions for conversion - Use util.img_as_float, util.img_as_ubyte to handle rescaling automatically when changing dtypes.
Grayscale for analysis - Most feature extraction and segmentation algorithms expect 2D grayscale arrays.
Check image shape - Always verify image.shape and image.dtype before processing.
Vectorize - Use NumPy operations instead of loops over pixels.
Apply filters before segmentation - Denoising (Gaussian, Median) significantly improves segmentation results.
Use label for object counting - measure.label is the standard way to identify connected components.
❌ DON'T
Manually rescale dtypes - Avoid image / 255.0; use util.img_as_float.
Ignore the "Coordinate Warning" - Be careful with (x, y) vs (row, col). scikit-image uses (row, col).
Modify the input image - Most functions return a new array; work with copies if you need to mutate.
Apply color-sensitive filters to grayscale - Some filters behave differently on 3D vs 2D arrays.
Anti-Patterns (NEVER)
image_float = image.astype(float )
from skimage import util
image_float = util.img_as_float(image)
for r in range (rows):
for c in range (cols):
if image[r, c] > 128 :
image[r, c] = 255
image[image > 0.5 ] = 1.0
plt.imshow(img1); plt.show()
plt.imshow(img2); plt.show()
fig, ax = plt.subplots(1 , 2 )
ax[0 ].imshow(img1, cmap='gray' )
ax[1 ].imshow(img2, cmap='gray' )
Filtering and Restoration (skimage.filters)
Denoising and Edge Detection from skimage import filters
edges_sobel = filters.sobel(image)
edges_canny = feature.canny(image, sigma=3 )
denoised = filters.median(image, morphology.disk(3 ))
val = filters.threshold_otsu(image)
binary = image > val
Morphology (skimage.morphology)
Shaping and Structural Analysis from skimage import morphology
struct_element = morphology.disk(5 )
eroded = morphology.erosion(binary, struct_element)
dilated = morphology.dilation(binary, struct_element)
opened = morphology.opening(binary, struct_element)
skeleton = morphology.skeletonize(binary)
clean_binary = morphology.remove_small_objects(binary, min_size=64 )
Segmentation (skimage.segmentation)
Separating Objects from skimage import segmentation, color
from scipy import ndimage as ndi
distance = ndi.distance_transform_edt(binary)
coords = feature.peak_local_max(distance, footprint=np.ones((3 , 3 )), labels=binary)
mask = np.zeros(distance.shape, dtype=bool )
mask[tuple (coords.T)] = True
markers, _ = ndi.label(mask)
labels = segmentation.watershed(-distance, markers, mask=binary)
segments = segmentation.slic(image, n_segments=100 , compactness=10 )
out = color.label2rgb(segments, image, kind='avg' )
Feature Detection (skimage.feature)
Keypoints and Textures from skimage import feature
lbp = feature.local_binary_pattern(image, P=8 , R=1 )
coords = feature.corner_peaks(feature.corner_harris(image), min_distance=5 )
blobs = feature.blob_dog(image, max_sigma=30 , threshold=.1 )
Measurements (skimage.measure)
Quantifying Results from skimage import measure
labels = measure.label(binary)
props = measure.regionprops(labels)
for prop in props:
print (f"Label: {prop.label} " )
print (f"Area: {prop.area} " )
print (f"Centroid: {prop.centroid} " )
print (f"Eccentricity: {prop.eccentricity} " )
contours = measure.find_contours(binary, 0.8 )
Practical Workflows
1. Particle Counting Pipeline def count_particles (image_path ):
img = color.rgb2gray(io.imread(image_path))
img_denoised = filters.gaussian(img, sigma=1 )
thresh = filters.threshold_otsu(img_denoised)
binary = img_denoised < thresh
binary = morphology.remove_small_objects(binary, 50 )
binary = morphology.closing(binary, morphology.disk(3 ))
labels = measure.label(binary)
return measure.regionprops(labels), labels
2. Micrograph Analysis (Nuclei Segmentation) def segment_nuclei (dna_image ):
"""Identify nuclei in a DAPI/Hoechst stained image."""
local_thresh = filters.threshold_local(dna_image, block_size=35 )
binary = dna_image > local_thresh
filled = ndi.binary_fill_holes(binary)
distance = ndi.distance_transform_edt(filled)
local_maxi = feature.peak_local_max(distance, indices=False , footprint=np.ones((15 , 15 )), labels=filled)
markers = measure.label(local_maxi)
labels = segmentation.watershed(-distance, markers, mask=filled)
return labels
3. Change Detection (Image Subtraction) def detect_change (img_before, img_after, threshold=0.1 ):
im1 = util.img_as_float(color.rgb2gray(img_before))
im2 = util.img_as_float(color.rgb2gray(img_after))
diff = np.abs (im1 - im2)
diff_clean = filters.median(diff, morphology.disk(2 ))
return diff_clean > threshold
Performance Optimization
Using skimage.util.view_as_windows from skimage.util import view_as_windows
patches = view_as_windows(image, (64 , 64 ), step=32 )
Parallel Processing
from joblib import Parallel, delayed
results = Parallel(n_jobs=-1 )(delayed(filters.gaussian)(img) for img in image_list)
Common Pitfalls and Solutions
Handling Multichannel Images
Memory issues with label
binary = morphology.remove_small_objects(binary, min_size=10 )
labels = measure.label(binary)
Coordinates: (X, Y) vs (Row, Col) confusion
coords = feature.peak_local_max(img)
plt.plot(coords[:, 1 ], coords[:, 0 ], 'r.' )
scikit-image provides the mathematical rigor needed for scientific discovery. By building on the NumPy ecosystem, it allows for a seamless workflow from raw sensor data to quantifiable insights.