Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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.
.claude/skills/bio-imaging-mass-cytometry-cell-segmentation/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-19 | ✗→✓ | ▲ Improved | — | — |
| case-05 | ✗→✓ | ▲ Improved | — | — |
| case-16 | ✗→✓ | ▲ Improved | — | — |
| case-14 | ✗→✓ | ▲ Improved | — | — |
| case-01 | ✗→✓ | ▲ Improved | — | — |
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:
pip show <package> then help(module.function) to check signatures<tool> --version then <tool> --help to confirm flagsIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
"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.
cellpose.models.Cellpose() for deep learning segmentationsteinbock segment for pipeline-based segmentationpythonfrom 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()}')
python# 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 )
pythonfrom 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]
bash# 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 masks
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.
pythonfrom 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')
pythonimport 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)
pythonfrom 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')
pythonimport tifffile # Save masks as labeled image tifffile.imwrite('cell_masks.tiff', masks.astype(np.uint16)) # Save single-cell data cell_info.to_csv('cell_info.csv', index=False) intensities.to_csv('cell_intensities.csv', index=False) # Create combined AnnData import anndata as ad adata = ad.AnnData(X=intensities.values) adata.var_names = channel_names adata.obs = cell_info # Add spatial coordinates adata.obsm['spatial'] = cell_info[['centroid_x', 'centroid_y']].values adata.write('imc_segmented.h5ad')
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-02 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +23 percentage points is the difference between those two pass rates over the 21 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.