PY-61

List Patch Origins under an Edge Rule

  • Medium
  • Image Geometry
  • Python

Task

Write list_patch_origins(image_shape, patch_shape, stride, edge_rule). Shapes and stride are (rows, columns) positive-integer pairs, and each patch dimension is no larger than its image dimension.

Return (row, column) origins in row-major order. Under "valid", use origins 0, stride, 2*stride, ... only while the complete patch fits. Under "cover", use those origins and also append image_size - patch_size on an axis when the regular sequence did not reach it. Combining the two axis lists must not create duplicate origins. Raise ValueError("unknown edge rule") for another rule.

Example

For image (7, 8), patch (3, 3), and stride (3, 3), valid row origins are [0, 3]; cover row origins are [0, 3, 4]. Cover column origins are [0, 3, 5], so cover returns nine row-major pairs.

Your implementation

Do not extract patch values, modify an input, print, or ask for input.