fix-dimensions: Update Image Dimensions in VOC Annotations¶
The fix-dimensions command reads actual image dimensions from image files and updates corresponding Pascal VOC annotation files with the correct values. This is useful for fixing annotations that have incorrect or missing size information.
Breaking change
This command now takes a single DATASET_DIR (expecting JPEGImages/ and Annotations/
subfolders -- the standard Pascal VOC devkit layout) instead of separate
ANNOTATION_DIR/IMAGE_DIR arguments. See generate and
split, which both write/read this same directory shape.
Usage¶
Parameters¶
DATASET_DIR: Dataset directory, expectingJPEGImages/andAnnotations/subfolders--output-dir: (Optional) Directory to save corrected annotations; if omitted,DATASET_DIR/Annotationsis updated in place--pretty-print: (Optional) Format the XML output with indentation (default: True)--verbose, -v: (Optional) Display detailed logging information
Data Modification
If --output-dir is not specified, the original annotation files will be modified directly.
Use the --output-dir option if you want to keep the original files unchanged.
How It Works¶
- The command associates annotation files with image files by matching their filename stems
- For each matched pair, it:
- Reads the actual dimensions of the image using the
imagesizelibrary - Updates or creates the
<size>element in the XML with correct<width>and<height>values - Writes the corrected XML to the output location
- Reads the actual dimensions of the image using the
- A summary of updated and unchanged files is provided
File Matching
- Images and annotation files are matched by filename (without extension)
- Files with different extensions but the same name will be matched (e.g.,
image1.xmlandimage1.jpg) - Annotations without matching images are reported but not modified
Efficient Processing
The imagesize library is used to efficiently read dimensions without loading entire images into memory,
making this command fast even with large image files.
Examples¶
Update annotations in-place:
Save corrected annotations to a new directory:
Enable verbose logging for troubleshooting: