Slice padding augmented duplicates

From wenmin-wu/ds-skills · View interactive version

Slice padding augmented duplicates is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Pad 3D volumes with fewer slices than required by duplicating existing slices with slight brightness variation via convertScaleAbs

How to use this skill

Skill file

Slice Padding with Augmented Duplicates

Overview

When a 3D volume has fewer slices than the target depth, zero-padding wastes model capacity on empty data. Instead, pad by duplicating randomly chosen existing slices with slight brightness augmentation (cv2.convertScaleAbs(alpha=1.2)). This fills the depth dimension with plausible content and acts as a mild data augmentation, better than both zero-padding and plain duplication.

Quick Start

import cv2
import random
import numpy as np

def pad_volume_with_augmented_slices(slices, target_depth, alpha=1.2, beta=0):
    """Pad a list of slices to target_depth by duplicating with brightness jitter."""
    while len(slices) < target_depth and slices:
        donor = random.choice(slices)
        augmented = cv2.convertScaleAbs(donor, alpha=alpha, beta=beta)
        slices.append(augmented)
    return slices[:target_depth]

flair_slices = [cv2.imread(p, 0) for p in flair_paths]
flair_slices = pad_volume_with_augmented_slices(flair_slices, target_depth=64)
volume = np.stack(flair_slices)

Workflow

  1. Load all available slices for the volume
  2. If count < target depth, randomly select an existing slice
  3. Apply cv2.convertScaleAbs(alpha, beta) for slight brightness change
  4. Append the augmented copy
  5. Repeat until target depth is reached

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.