Skip to main content

Aspect-Pad 📐

CI PyPI - Version PyPI - Python Version PyPI - License

A lightweight, PyTorch-compatible computer vision transform that perfectly scales and mathematically pads images without distorting their aspect ratios.

When feeding unconstrained real-world images (like drone photography, medical scans, or OCR inputs) into Convolutional Neural Networks (CNNs), standard resizing often squishes and warps the data. Aspect-Pad intelligently scales the image and dynamically pads the remaining space to create a perfect square (or custom rectangle) tensor, preserving the original spatial features of your dataset.

🚀 Installation

You can install the package directly from PyPI:

pip install aspect-pad

💻 Quick Start

Aspect-Pad works natively with PIL Images and drops directly into standard PyTorch transforms.

import torchvision.transforms as transforms
from PIL import Image
from aspect_pad import AspectPad

# Load a raw, irregularly-shaped image
raw_image = Image.open("messy_drone_photo.jpg")

# Target a 512x512 square tensor, dynamically padding the empty space with black (0)
pipeline = transforms.Compose([
    AspectPad(target_size=512, fill=0),
    transforms.ToTensor()
])

# Pass the image through the pipeline
tensor_image = pipeline(raw_image)
print(tensor_image.shape) # Output: torch.Size([3, 512, 512])

⚙️ Features

  • Drop-in PyTorch Compatibility: Built to work flawlessly inside torchvision.transforms.Compose.

  • Universal "Anti-Squish" Math: Automatically calculates the delta for wide or tall images and centers the original image perfectly.

  • Custom Target Sizes: Target a single integer for standard square CNNs (e.g., 224 for ResNet) or pass a tuple for specific architectures (e.g., (1920, 1080)).

  • Custom Fill Colors: Support for grayscale padding (e.g., 0 for black), RGB padding (e.g., (255, 255, 255) for white), or any arbitrary background color.


Author: Shin Thant Tun

Release files for aspect-pad 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aspect-pad 0.1.2
File Size Uploaded
aspect_pad-0.1.2.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aspect-pad 0.1.2
File Interpreter ABI Platform
aspect_pad-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / aspect_pad-0.1.2.tar.gz

Download URL aspect_pad-0.1.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8c494a988caa4b35cbb3333c6aa3c8bdf7bfd14fd417921d045d8c6e24dc2b53
BLAKE2b-256 checksum
How to use checksums
46aac02978e1c876fdd0db95f871d23cd2ad1574518dc12bb0bf79886cc43699
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / aspect_pad-0.1.2-py3-none-any.whl

Download URL aspect_pad-0.1.2-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6aade9472912e241b0b42e95970ace54c761b89b8cdca015d64a344c65d2ca1
BLAKE2b-256 checksum
How to use checksums
6a88132d0e6dec5d80d84c571c61a0dd0646199075701ea969abc9b436201d30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.3

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page