Skip to content
Back to skills

Slice Padding Augmented Duplicates

ASecurity

Pad 3D volumes with fewer slices than required by duplicating existing slices with slight brightness variation via convertScaleAbs

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
toolspython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill slice-padding-augmented-duplicates --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Slice Padding Augmented Duplicates?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Slice Padding Augmented Duplicates
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-slice-padding-augmented-duplicates/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-slice-padding-augmented-duplicates)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cv-slice-padding-augmented-duplicates
description: Pad 3D volumes with fewer slices than required by duplicating existing slices with slight brightness variation via convertScaleAbs
---

# 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

```python
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

- **alpha**: 1.1-1.3 provides subtle variation; higher values distort tissue contrast
- **Random vs sequential**: random selection provides more diversity than repeating the last slice
- **vs zero-pad**: augmented duplicates provide real texture; zeros create sharp boundary artifacts
- **vs interpolation**: duplication is simpler and preserves original slice quality

## References

- [[TF]: 3D & 2D Model for Brain Tumor Classification](https://www.kaggle.com/code/ipythonx/tf-3d-2d-model-for-brain-tumor-classification)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.