Center Crop
A center crop keeps the rectangular region at the middle of an image and removes pixels around its edges. It is a simple way to make images a consistent size while preserving what photographers and datasets frequently place near the center: the main subject.
How it works
Suppose an image is 640 × 480 pixels and a model expects 224 × 224 pixels. A center crop selects a 224 × 224 square whose center aligns with the image’s center, then discards everything outside that square. For a crop of width W and height H, the top-left crop position is approximately:
x = (image_width - W) / 2
y = (image_height - H) / 2
Unlike resizing, cropping does not squeeze or stretch objects. The trade-off is that it throws away visual information near the borders.
Where it is used
- Image classification: During evaluation, a model commonly receives a resized image followed by a center crop, producing a repeatable input without randomness.
- Face recognition: After a face has been aligned and placed near the middle, center cropping can retain the face while standardizing its dimensions.
- Visual inspection: On a production line, it can remove irrelevant camera borders when the inspected part is reliably centered.
Why the choice matters
Center cropping assumes the important content lies near the center. That assumption works well for carefully framed photographs, but it can fail for autonomous-driving images, where pedestrians, signs, and vehicles can appear at the edges. In object detection or segmentation, an untracked crop can cut through an object and invalidate its bounding box or pixel mask. Training pipelines therefore commonly use random crops to teach models to handle shifted subjects, while center crops provide stable, fair evaluation. In torchvision, this transform appears as torchvision.transforms.CenterCrop.
Center crop is a geometric image transform that extracts a fixed-size rectangular region centered on the image, discarding pixels near its borders. It standardizes input dimensions while preserving the image’s central content. In computer vision, it provides deterministic preprocessing for evaluation and inference, especially when models expect fixed-resolution inputs; however, important objects near image edges can be removed.
Imagine trimming a photo so that the most likely subject stays in view: you cut away equal amounts from the top and bottom, or from the left and right, while keeping the middle. That is a center crop.
In computer vision, a center crop takes the central part of an image and discards its outer edges. It is often used when an AI system needs every picture to have the same shape or size. For example, a photo may be trimmed to a square around its middle before being shown to an image-recognition model.
It is simple and predictable, but it assumes the important thing is near the center—usually true for portraits and product photos, but not always.