Skip to main content

haechan

Computer vision utilities for dataset visualization.

Installation

pip install haechan

Optional external tools:

brew install ffmpeg    # vid_resize, save_video에 필요
brew install gifsicle  # save_gif optimize=True에 필요

Usage

blend

세그멘테이션 마스크를 이미지에 오버레이합니다.

import numpy as np
from haechan import blend

img  = np.array(Image.open("image.jpg"))   # H x W x 3, uint8
mask = np.array(Image.open("mask.png"))    # H x W, int (class index)
fg   = mask > 0                            # 전경 boolean mask

blended = blend(img, mask, fg)

label

마스크 중심에 클래스 이름 태그를 그립니다. 배경색 밝기에 따라 텍스트 색을 자동 선택하고 stroke를 추가해 어떤 이미지에서도 가독성을 보장합니다. 마스크 bbox에 텍스트가 들어가지 않으면 폰트 크기를 자동으로 줄입니다.

from PIL import Image, ImageDraw
from haechan import label

pil_img = Image.fromarray(blended)
draw    = ImageDraw.Draw(pil_img)

label(draw, mask == 1, text="person", color=(255, 0, 0))

mask와 이미지 크기가 달라도 자동으로 좌표를 스케일링합니다.

img_resize

이미지와 마스크를 함께 리사이즈합니다. aspect ratio를 유지하며 긴 쪽을 max_size 이하로 줄입니다.

from haechan import img_resize

img, mask = img_resize(img, mask, max_size=640)

# 마스크 없이
img, = img_resize(img, max_size=480)

# boxes도 함께 스케일링
img, mask = img_resize(img, mask, boxes=boxes, max_size=480)

vid_resize

비디오 파일을 프레임 리스트로 디코딩하면서 리사이즈합니다. ffmpeg가 필요합니다.

from haechan import vid_resize

frames, mask_seq = vid_resize("input.mp4", mask_seq, max_size=480)

.mp4, .avi, .mov 등 ffmpeg가 지원하는 모든 포맷을 입력으로 받습니다.

save_img

from haechan import save_img

save_img(blended, "output.jpg")   # numpy array 또는 PIL Image
save_img(pil_img, "output.png")

save_gif

from haechan import save_gif

frames = [Image.open(f"frame{i}.png") for i in range(10)]

save_gif(frames, "output.gif", duration=200)

# gifsicle로 후처리 압축 (--lossy=80 --optimize=3)
save_gif(frames, "output.gif", duration=200, optimize=True)

save_video

PIL Image 리스트를 MP4로 저장합니다. ffmpeg가 필요합니다.

from haechan import save_video

save_video(frames, "output.mp4", fps=10)

palette / get_colors

from haechan import palette, get_colors

colors = palette()                  # 254색 고정 팔레트, np.ndarray shape (254, 3) uint8
colors = get_colors(num_classes=80) # 원하는 클래스 수만큼

License

MIT

Metadata

Release files for haechan 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haechan 0.2.1
File Size Uploaded
haechan-0.2.1.tar.gz 1.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for haechan 0.2.1
File Interpreter ABI Platform
haechan-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 2.3 MB

Release files / haechan-0.2.1.tar.gz

Download URL haechan-0.2.1.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
75d0c52764c99f362c2744b5335b49a5073dc5a49fe4f63c67680f1cd7834685
BLAKE2b-256 checksum
How to use checksums
99354775b62edd16ef7c06641817210f9fc2fbd2547a9743100047d27baf5dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / haechan-0.2.1-py3-none-any.whl

Download URL haechan-0.2.1-py3-none-any.whl
Size 1.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
29eb4e8e04f480b9bad9ea1e5a1283064f63fc4f09f254a2dc3cf74e0cf37804
BLAKE2b-256 checksum
How to use checksums
0f3e2964e57a8c9d4db4dab7620b32324e15982501dc3b15f1491deca35badd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

1 release file

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page