|
| 1 | +"""Configuration constants for color checker card grid layout. |
| 2 | +
|
| 3 | +This module defines the standard layout for the X-Rite ColorChecker Classic |
| 4 | +24-patch card, which has a 6x4 grid (6 columns, 4 rows = 24 patches total). |
| 5 | +""" |
| 6 | + |
| 7 | +from typing import Final |
| 8 | + |
| 9 | +# ============================================================================ |
| 10 | +# Grid Dimensions |
| 11 | +# ============================================================================ |
| 12 | + |
| 13 | +GRID_ROWS: Final[int] = 4 |
| 14 | +"""Number of rows in the color checker grid.""" |
| 15 | + |
| 16 | +GRID_COLS: Final[int] = 6 |
| 17 | +"""Number of columns in the color checker grid.""" |
| 18 | + |
| 19 | +TOTAL_PATCHES: Final[int] = GRID_ROWS * GRID_COLS # 24 |
| 20 | +"""Total number of patches in the color checker card.""" |
| 21 | + |
| 22 | + |
| 23 | +# ============================================================================ |
| 24 | +# Grid Position Indices |
| 25 | +# ============================================================================ |
| 26 | + |
| 27 | +ROW_END_INDICES: Final[frozenset[int]] = frozenset([5, 11, 17, 23]) |
| 28 | +"""Indices of patches at the end of each row (rightmost column).""" |
| 29 | + |
| 30 | +ROW_START_INDICES: Final[frozenset[int]] = frozenset([0, 6, 12, 18]) |
| 31 | +"""Indices of patches at the start of each row (leftmost column).""" |
| 32 | + |
| 33 | +COL_END_INDICES: Final[frozenset[int]] = frozenset(range(18, 24)) |
| 34 | +"""Indices of patches in the last row (bottom row).""" |
| 35 | + |
| 36 | +COL_START_INDICES: Final[frozenset[int]] = frozenset(range(0, 6)) |
| 37 | +"""Indices of patches in the first row (top row).""" |
| 38 | + |
| 39 | + |
| 40 | +# ============================================================================ |
| 41 | +# Neighbor Offsets |
| 42 | +# ============================================================================ |
| 43 | + |
| 44 | +NEIGHBOR_RIGHT_OFFSET: Final[int] = 1 |
| 45 | +"""Index offset to get right neighbor patch.""" |
| 46 | + |
| 47 | +NEIGHBOR_LEFT_OFFSET: Final[int] = -1 |
| 48 | +"""Index offset to get left neighbor patch.""" |
| 49 | + |
| 50 | +NEIGHBOR_BOTTOM_OFFSET: Final[int] = GRID_COLS # 6 |
| 51 | +"""Index offset to get bottom neighbor patch (next row).""" |
| 52 | + |
| 53 | +NEIGHBOR_TOP_OFFSET: Final[int] = -GRID_COLS # -6 |
| 54 | +"""Index offset to get top neighbor patch (previous row).""" |
| 55 | + |
| 56 | + |
| 57 | +# ============================================================================ |
| 58 | +# Visualization Defaults |
| 59 | +# ============================================================================ |
| 60 | + |
| 61 | +DEFAULT_GRID_FIGSIZE_WIDTH: Final[int] = 15 |
| 62 | +"""Default figure width for grid visualizations.""" |
| 63 | + |
| 64 | +DEFAULT_GRID_FIGSIZE_HEIGHT_PER_ROW: Final[int] = 4 |
| 65 | +"""Default figure height per row for grid visualizations.""" |
| 66 | + |
| 67 | + |
| 68 | +# ============================================================================ |
| 69 | +# Detection Defaults |
| 70 | +# ============================================================================ |
| 71 | + |
| 72 | +MIN_PATCHES_REQUIRED: Final[int] = 24 |
| 73 | +"""Minimum number of patches required for valid detection.""" |
| 74 | + |
| 75 | +DEFAULT_CONFIDENCE_THRESHOLD: Final[float] = 0.25 |
| 76 | +"""Default confidence threshold for card detection.""" |
| 77 | + |
| 78 | +DEFAULT_IOU_THRESHOLD: Final[float] = 0.7 |
| 79 | +"""Default Intersection over Union threshold for NMS.""" |
| 80 | + |
| 81 | + |
| 82 | +# ============================================================================ |
| 83 | +# Helper Functions |
| 84 | +# ============================================================================ |
| 85 | + |
| 86 | + |
| 87 | +def is_row_end(index: int) -> bool: |
| 88 | + """Check if patch index is at row end (rightmost column). |
| 89 | +
|
| 90 | + Parameters |
| 91 | + ---------- |
| 92 | + index : int |
| 93 | + Patch index (0-23) |
| 94 | +
|
| 95 | + Returns |
| 96 | + ------- |
| 97 | + bool |
| 98 | + True if patch is at row end |
| 99 | + """ |
| 100 | + return index in ROW_END_INDICES |
| 101 | + |
| 102 | + |
| 103 | +def is_row_start(index: int) -> bool: |
| 104 | + """Check if patch index is at row start (leftmost column). |
| 105 | +
|
| 106 | + Parameters |
| 107 | + ---------- |
| 108 | + index : int |
| 109 | + Patch index (0-23) |
| 110 | +
|
| 111 | + Returns |
| 112 | + ------- |
| 113 | + bool |
| 114 | + True if patch is at row start |
| 115 | + """ |
| 116 | + return index in ROW_START_INDICES |
| 117 | + |
| 118 | + |
| 119 | +def get_row_number(index: int) -> int: |
| 120 | + """Get row number (0-3) for a given patch index. |
| 121 | +
|
| 122 | + Parameters |
| 123 | + ---------- |
| 124 | + index : int |
| 125 | + Patch index (0-23) |
| 126 | +
|
| 127 | + Returns |
| 128 | + ------- |
| 129 | + int |
| 130 | + Row number (0 for top row, 3 for bottom row) |
| 131 | + """ |
| 132 | + return index // GRID_COLS |
| 133 | + |
| 134 | + |
| 135 | +def get_col_number(index: int) -> int: |
| 136 | + """Get column number (0-5) for a given patch index. |
| 137 | +
|
| 138 | + Parameters |
| 139 | + ---------- |
| 140 | + index : int |
| 141 | + Patch index (0-23) |
| 142 | +
|
| 143 | + Returns |
| 144 | + ------- |
| 145 | + int |
| 146 | + Column number (0 for leftmost, 5 for rightmost) |
| 147 | + """ |
| 148 | + return index % GRID_COLS |
0 commit comments