/bio-imaging-mass-cytometry-cell-segmentation
Cell segmentation from multiplexed tissue images. Covers deep learning (Cellpose, Mesmer) and classical approaches for nuclear and whole-cell segmentation. Use when extracting single-cell data from IMC or MIBI images after preprocessing.
$ npx -y skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-imaging-mass-cytometry-cell-segmentation --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/bio-imaging-mass-cytometry-cell-segmentation
Context preview
The summary Claude sees to decide when to auto-load this skill.
Cell segmentation from multiplexed tissue images. Covers deep learning (Cellpose, Mesmer) and classical approaches for nuclear and whole-cell segmentation. Use when extracting single-cell data from IMC or MIBI images after preprocessing.
SKILL.md
bio-imaging-mass-cytometry-cell-segmentation.SKILL.mdname: bio-imaging-mass-cytometry-cell-segmentation
description: Cell segmentation from multiplexed tissue images. Covers deep learning (Cellpose, Mesmer) and classical approaches for nuclear and whole-cell segmentation. Use when extracting single-cell data from IMC or MIBI images after preprocessing.
tool_type: python
primary_tool: cellpose
Version Compatibility
Reference examples tested with: Cellpose 3.0+, anndata 0.10+, matplotlib 3.8+, numpy 1.26+, pandas 2.2+, scanpy 1.10+, steinbock 0.16+
Before using code patterns, verify installed versions match. If versions differ:
- Python: `pip show <package>` then `help(module.function)` to check signatures
- CLI: `<tool> --version` then `<tool> --help` to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Cell Segmentation for IMC
**"Segment cells from my IMC images"** → Identify individual cell boundaries in multiplexed imaging data using deep learning (Cellpose) or watershed-based approaches for single-cell extraction.
- Python: `cellpose.models.Cellpose()` for deep learning segmentation
- CLI: `steinbock segment` for pipeline-based segmentation
Cellpose Segmentation
from cellpose import models, io
import numpy as np
import tifffile
# Load image
img = tifffile.imread('processed.tiff')
# Extract nuclear channel (e.g., DNA1)
nuclear_channel = img[0] # Adjust index based on panel
# Initialize Cellpose model
model = models.Cellpose(model_type='nuclei', gpu=True)
# Run segmentation
masks, flows, styles, diams = model.eval(
nuclear_channel,
diameter=30, # Average nucleus diameter in pixels
flow_threshold=0.4,
cellprob_threshold=0.0
)
# masks contains integer labels for each cell
print(f'Cells segmented: {masks.max()}')Whole-Cell Segmentation with Cellpose
# Use membrane marker for whole-cell
membrane_channel = img[1] # e.g., CD45
# Combine nuclear and membrane for cyto model
model = models.Cellpose(model_type='cyto2', gpu=True)
# Create 2-channel input [membrane, nuclear]
img_input = np.stack([membrane_channel, nuclear_channel])
masks, flows, styles, diams = model.eval(
img_input,
channels=[1, 2], # [membrane, nuclear]
diameter=50,
flow_threshold=0.4
)Mesmer (DeepCell)
from deepcell.applications import Mesmer
# Initialize Mesmer
app = Mesmer()
# Prepare input: (batch, H, W, 2) - [nuclear, membrane]
img_input = np.stack([nuclear_channel, membrane_channel], axis=-1)
img_input = np.expand_dims(img_input, axis=0)
# Segment
predictions = app.predict(
img_input,
image_mpp=1.0, # Microns per pixel
compartment='whole-cell' # or 'nuclear'
)
masks = predictions[0, :, :, 0]steinbock Segmentation
# Using steinbock with Cellpose
steinbock segment cellpose \
--img processed \
--model cyto2 \
--channelwise \
--nuclear-channel 0 \
--membrane-channel 1 \
-o masks
# Using steinbock with DeepCell
steinbock segment deepcell \
--img processed \
--nuclear-channel 0 \
--membrane-channel 1 \
-o masksExtract Single-Cell Data
**Goal:** Convert a segmented cell mask and multi-channel image stack into a per-cell expression matrix suitable for downstream phenotyping and spatial analysis.
**Approach:** Iterate over regionprops of the label mask, compute mean intensity per channel within each cell's pixels, and collect morphological features (area, centroid, eccentricity) into a structured DataFrame.
from skimage import measure
import pandas as pd
def extract_single_cell_data(img, masks, channel_names):
'''Extract mean intensity per cell per channel'''
# Region properties
props = measure.regionprops(masks)
# Cell info
cell_data = []
intensities = []
for prop in props:
# Basic properties
cell_info = {
'cell_id': prop.label,
'area': prop.area,
'centroid_x': prop.centroid[1],
'centroid_y': prop.centroid[0],
'eccentricity': prop.eccentricity
}
cell_data.append(cell_info)
# Mean intensity per channel
cell_mask = masks == prop.label
cell_intensities = [img[c][cell_mask].mean() for c in range(len(channel_names))]
intensities.append(cell_intensities)
cell_df = pd.DataFrame(cell_data)
intensity_df = pd.DataFrame(intensities, columns=channel_names)
return cell_df, intensity_df
cell_info, intensities = extract_single_cell_data(img, masks, channel_names)
print(f'Extracted data for {len(cell_info)} cells')Quality Control
import matplotlib.pyplot as plt
def qc_segmentation(img, masks, nuclear_channel_idx=0):
'''Visualize segmentation quality'''
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
# Nuclear channel
axes[0].imshow(img[nuclear_channel_idx], cmap='gray')
axes[0].set_title('Nuclear Channel')
# Segmentation masks
axes[1].imshow(masks, cmap='tab20')
axes[1].set_title(f'Segmentation ({masks.max()} cells)')
# Overlay
axes[2].imshow(img[nuclear_channel_idx], cmap='gray')
axes[2].contour(masks, colors='red', linewidths=0.5)
axes[2].set_title('Overlay')
for ax in axes:
ax.axis('off')
plt.tight_layout()
plt.savefig('segmentation_qc.png', dpi=150)
plt.close()
# Statistics
props = measure.regionprops(masks)
areas = [p.area for p in props]
print(f'Cells: {len(props)}')
print(f'Area: mean={np.mean(areas):.1f}, median={np.median(areas):.1f}')
qc_segmentation(img, masks)Expand Nuclei to Cells
from skimage.segmentation import expand_labels
# If only nuclear segmentation available, expand to approximate cells
nuclear_masks = masks # From nuclear segmentation
expanded_masks = expand_labels(nuclear_masks, distance=10)
print(f'Expanded masks from nuclei')
``
Read more
name: bio-imaging-mass-cytometry-cell-segmentation description: Cell segmentation from multiplexed tissue images. Covers deep learning (Cellpose, Mesmer) and classical approaches for nuclear and whole-cell segmentation. Use when extracting single-cell data from IMC or MIBI images after preprocessing. tool_type: python primary_tool: cellpose
Version Compatibility
Reference examples tested with: Cellpose 3.0+, anndata 0.10+, matplotlib 3.8+, numpy 1.26+, pandas 2.2+, scanpy 1.10+, steinbock 0.16+
Before using code patterns, verify installed versions match. If versions differ:
- Python: `pip show <package>` then `help(module.function)` to check signatures
- CLI: `<tool> --version` then `<tool> --help` to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Cell Segmentation for IMC
**"Segment cells from my IMC images"** → Identify individual cell boundaries in multiplexed imaging data using deep learning (Cellpose) or watershed-based approaches for single-cell extraction.
- Python: `cellpose.models.Cellpose()` for deep learning segmentation
- CLI: `steinbock segment` for pipeline-based segmentation
Cellpose Segmentation
from cellpose import models, io
import numpy as np
import tifffile
# Load image
img = tifffile.imread('processed.tiff')
# Extract nuclear channel (e.g., DNA1)
nuclear_channel = img[0] # Adjust index based on panel
# Initialize Cellpose model
model = models.Cellpose(model_type='nuclei', gpu=True)
# Run segmentation
masks, flows, styles, diams = model.eval(
nuclear_channel,
diameter=30, # Average nucleus diameter in pixels
flow_threshold=0.4,
cellprob_threshold=0.0
)
# masks contains integer labels for each cell
print(f'Cells segmented: {masks.max()}')Whole-Cell Segmentation with Cellpose
# Use membrane marker for whole-cell
membrane_channel = img[1] # e.g., CD45
# Combine nuclear and membrane for cyto model
model = models.Cellpose(model_type='cyto2', gpu=True)
# Create 2-channel input [membrane, nuclear]
img_input = np.stack([membrane_channel, nuclear_channel])
masks, flows, styles, diams = model.eval(
img_input,
channels=[1, 2], # [membrane, nuclear]
diameter=50,
flow_threshold=0.4
)Mesmer (DeepCell)
from deepcell.applications import Mesmer
# Initialize Mesmer
app = Mesmer()
# Prepare input: (batch, H, W, 2) - [nuclear, membrane]
img_input = np.stack([nuclear_channel, membrane_channel], axis=-1)
img_input = np.expand_dims(img_input, axis=0)
# Segment
predictions = app.predict(
img_input,
image_mpp=1.0, # Microns per pixel
compartment='whole-cell' # or 'nuclear'
)
masks = predictions[0, :, :, 0]steinbock Segmentation
# Using steinbock with Cellpose
steinbock segment cellpose \
--img processed \
--model cyto2 \
--channelwise \
--nuclear-channel 0 \
--membrane-channel 1 \
-o masks
# Using steinbock with DeepCell
steinbock segment deepcell \
--img processed \
--nuclear-channel 0 \
--membrane-channel 1 \
-o masksExtract Single-Cell Data
**Goal:** Convert a segmented cell mask and multi-channel image stack into a per-cell expression matrix suitable for downstream phenotyping and spatial analysis.
**Approach:** Iterate over regionprops of the label mask, compute mean intensity per channel within each cell's pixels, and collect morphological features (area, centroid, eccentricity) into a structured DataFrame.
from skimage import measure
import pandas as pd
def extract_single_cell_data(img, masks, channel_names):
'''Extract mean intensity per cell per channel'''
# Region properties
props = measure.regionprops(masks)
# Cell info
cell_data = []
intensities = []
for prop in props:
# Basic properties
cell_info = {
'cell_id': prop.label,
'area': prop.area,
'centroid_x': prop.centroid[1],
'centroid_y': prop.centroid[0],
'eccentricity': prop.eccentricity
}
cell_data.append(cell_info)
# Mean intensity per channel
cell_mask = masks == prop.label
cell_intensities = [img[c][cell_mask].mean() for c in range(len(channel_names))]
intensities.append(cell_intensities)
cell_df = pd.DataFrame(cell_data)
intensity_df = pd.DataFrame(intensities, columns=channel_names)
return cell_df, intensity_df
cell_info, intensities = extract_single_cell_data(img, masks, channel_names)
print(f'Extracted data for {len(cell_info)} cells')Quality Control
import matplotlib.pyplot as plt
def qc_segmentation(img, masks, nuclear_channel_idx=0):
'''Visualize segmentation quality'''
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
# Nuclear channel
axes[0].imshow(img[nuclear_channel_idx], cmap='gray')
axes[0].set_title('Nuclear Channel')
# Segmentation masks
axes[1].imshow(masks, cmap='tab20')
axes[1].set_title(f'Segmentation ({masks.max()} cells)')
# Overlay
axes[2].imshow(img[nuclear_channel_idx], cmap='gray')
axes[2].contour(masks, colors='red', linewidths=0.5)
axes[2].set_title('Overlay')
for ax in axes:
ax.axis('off')
plt.tight_layout()
plt.savefig('segmentation_qc.png', dpi=150)
plt.close()
# Statistics
props = measure.regionprops(masks)
areas = [p.area for p in props]
print(f'Cells: {len(props)}')
print(f'Area: mean={np.mean(areas):.1f}, median={np.median(areas):.1f}')
qc_segmentation(img, masks)Expand Nuclei to Cells
from skimage.segmentation import expand_labels # If only nuclear segmentation available, expand to approximate cells nuclear_masks = masks # From nuclear segmentation expanded_masks = expand_labels(nuclear_masks, distance=10) print(f'Expanded masks from nuclei') ``
The largest open-source medical AI skill library for OpenClaw.
Other skills on openclaw-medical-skills.
- /aav-vector-design-agent
<!--
Open skill - /adaptyv
Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use
Open skill - /adhd-daily-planner
Time-blind friendly planning, executive function support, and daily structure for ADHD brains. Specializes in realistic time estimation, dopamine-aware task design, and building systems that
Open skill - /aeon
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations
Open skill - /agent-browser
Browse the web for any task — research topics, read articles, interact with web apps, fill forms, take screenshots, extract data, and test web pages. Use whenever a browser would be useful, not just when the user explicitly asks.
Open skill - /agentd-drug-discovery
<!--
Open skill

