OpenParable
Skip to content
← Back to skills

Image Aspect Ratio Filter

Documents
image_aspect_ratio_filter

Image Aspect Ratio Filter is an Agent Skill for documents published in the cas-bigdatalab/piflow repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

图像长宽比过滤器。过滤图像长宽比不在指定范围内的样本。 当用户提到图像长宽比、图片比例过滤、图像尺寸筛选、图像宽高比等需求时使用此skill。 即使用户没有明确说出"长宽比",只要任务涉及根据图像宽高比来筛选数据, 就应该使用此skill。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/cas-bigdatalab/piflow/blob/HEAD/workspace/skills/image_aspect_ratio_filter/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/image-aspect-ratio-filter, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Image Aspect Ratio Filter 图像长宽比过滤 Skill

功能概述

本skill根据图像的长宽比(宽/高)进行过滤,只保留长宽比在指定范围内的图像。 常用于筛选特定比例的图像,如正方形、横屏、竖屏等。

触发条件

当用户请求以下任务时,应使用此skill:

  • 图像长宽比过滤
  • 图片比例筛选
  • 图像尺寸过滤
  • 图像宽高比筛选
  • 筛选正方形图像
  • 筛选横屏/竖屏图像

核心参数说明

必需参数

参数说明
--input输入JSON文件路径
--output输出JSON文件路径

可选参数

参数说明默认值
--min_ratio最小长宽比0.333
--max_ratio最大长宽比3.0
--any_or_all多图像过滤策略any
--image_key图像字段的键名images

输入文件格式

[
  {"images": ["/path/to/image1.jpg"]},
  {"images": ["/path/to/image2.jpg"]},
  {"images": ["/path/to/image3.png"]}
]

长宽比说明

  • 长宽比 = 宽 / 高
  • 1.0 = 正方形
  • < 1.0 = 竖屏图像
  • 1.0 = 横屏图像

使用方法

默认参数过滤(长宽比0.333-3.0)

python scripts/run_image_aspect_ratio_filter.py \
  --input ./input.json \
  --output ./output.json

筛选正方形图像(长宽比接近1.0)

python scripts/run_image_aspect_ratio_filter.py \
  --input ./input.json \
  --output ./output.json \
  --min_ratio 0.9 \
  --max_ratio 1.1

筛选横屏图像

python scripts/run_image_aspect_ratio_filter.py \
  --input ./input.json \
  --output ./output.json \
  --min_ratio 1.0

筛选竖屏图像

python scripts/run_image_aspect_ratio_filter.py \
  --input ./input.json \
  --output ./output.json \
  --max_ratio 1.0

过滤策略说明

策略说明
any任一图像满足条件即保留(默认)
all所有图像都满足条件才保留

输出示例

命令行输出:

[OK] Image aspect ratio filtering completed!
   Min ratio: 0.333
   Max ratio: 3.0
   Strategy: any
   Original documents: 3
   Filtered documents: 2
   Removed documents: 1
   Input file: ./input.json
   Output file: ./output.json

输出JSON格式:

[
  {"images": ["/path/to/image1.jpg"]},
  {"images": ["/path/to/image2.jpg"]}
]

环境要求

安装依赖: 本SKILL使用依赖 data_juicer,请在调用前安装好python环境并安装data_juicer:

pip install py-data-juicer

注意事项

  1. 图像路径:输入JSON中的图像路径应为绝对路径或相对于工作目录的路径
  2. 长宽比计算:宽 / 高,1.0 表示正方形
  3. 支持格式:支持 PNG、JPG、JPEG 等常见图像格式
  4. 适用场景:筛选特定比例的图像、过滤极端比例图像