Apply random brightness jitter at synthesis time

Per-plate HSV V scaling in [0.55, 1.45] for cheap color diversity. Heavy
geometric augmentation belongs in the training transforms (next step) so
each epoch sees a different version, not in synthesis.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
main
songhyeonsu 1 month ago
parent 6abac39c46
commit 640a5bcb83

@ -50,6 +50,13 @@ REGION_MAP = {
}
def random_bright(img: np.ndarray, scale_range=(0.55, 1.45)) -> np.ndarray:
"""HSV V 채널 곱하기로 plate 전체 밝기 무작위 변경. 색상 다양성용."""
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV).astype(np.float32)
hsv[:, :, 2] = np.clip(hsv[:, :, 2] * random.uniform(*scale_range), 0, 255)
return cv2.cvtColor(hsv.astype(np.uint8), cv2.COLOR_HSV2BGR)
class LPGenerator:
def __init__(self, asset_dir: Path):
self.asset = Path(asset_dir)
@ -189,6 +196,7 @@ def main():
p.add_argument("--types", default="1,2,3,4", help="포함할 type (콤마 구분)")
p.add_argument("--type_weights", default=None,
help="--types 순서대로 콤마 구분 가중치. 미지정 시 한국 도로 분포 기본값 사용.")
p.add_argument("--no_bright", action="store_true", help="random_bright 끄기 (디버깅용)")
p.add_argument("--dict", default=None, help="검증용 dict 경로 (선택)")
p.add_argument("--seed", type=int, default=42)
args = p.parse_args()
@ -240,6 +248,8 @@ def main():
plate, top, bot = fn()
label = make_label_two_line(plate, top, bot)
seen_chars.update(top); seen_chars.update(bot)
if not args.no_bright:
plate = random_bright(plate)
fname = f"{i:06d}.jpg"
cv2.imwrite(str(img_dir / fname), plate)
records.append((f"images/{fname}", json.dumps(label, ensure_ascii=False)))

Loading…
Cancel
Save