SKILL.md
Version Compatibility
Reference examples tested with: matplotlib 3.8+, numpy 1.26+, pandas 2.2+, scikit-learn 1.4+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Interactive Annotation
"Manually annotate cell types in my IMC data" → Interactively label cells using napari visualization with marker overlays for training classifiers or validating automated phenotyping results.
- Python:
napari.Viewer()with label layer for interactive annotation
Napari-Based Annotation
import napari
import numpy as np
from skimage import io
import pandas as pd
# Load IMC image stack
image_stack = io.imread('imc_image.tiff') # (C, H, W)
segmentation_mask = io.imread('cell_segmentation.tiff')
# Create napari viewer
viewer = napari.Viewer()
# Add channels as separate layers for visualization
channel_names = ['CD45', 'CD3', 'CD68', 'panCK', 'DNA']
for i, name in enumerate(channel_names):
viewer.add_image(image_stack[i], name=name, visible=False, colormap='gray', blending='additive')
# Add segmentation
viewer.add_labels(segmentation_mask, name='Cells')
# Add annotation layer (start empty)
annotation_layer = viewer.add_labels(
np.zeros_like(segmentation_mask),
name='Cell_Types'
)
# Define cell types
cell_type_mapping = {1: 'T_cell', 2: 'Macrophage', 3: 'Epithelial', 4: 'Stromal', 5: 'Other'}
Marker-Guided Annotation
def create_marker_overlay(image_stack, channel_indices, colors):
'''Create RGB overlay of selected markers for easier annotation.'''
h, w = image_stack.shape[1:]
overlay = np.zeros((h, w, 3), dtype=np.float32)
for idx, color in zip(channel_indices, colors):
channel = image_stack[idx].astype(np.float32)
channel = (channel - channel.min()) / (channel.max() - channel.min() + 1e-8)
for c, weight in enumerate(color):
overlay[:, :, c] += channel * weight
overlay = np.clip(overlay, 0, 1)
return overlay
# Create T cell overlay (CD3=green, CD45=blue)
t_cell_overlay = create_marker_overlay(
image_stack,
channel_indices=[0, 1], # CD45, CD3
colors=[[0, 0, 1], [0, 1, 0]] # Blue, Green
)
# Create tumor overlay (panCK=red)
tumor_overlay = create_marker_overlay(
image_stack,
channel_indices=[3], # panCK
colors=[[1, 0, 0]] # Red
)
# Add overlays to viewer
viewer.add_image(t_cell_overlay, name='T_cell_markers', visible=True)
viewer.add_image(tumor_overlay, name='Tumor_markers', visible=False)
