def del_alpha_channel(rgba,
background=(255,255,255)):
''' 알파채널 제거
'''
row, col, ch = rgba.shape
if ch == 3:
return rgba
assert ch == 4, 'RGBA image has 4 channels.'
rgb = np.zeros( (row, col, 3), dtype='float32' )
r, g, b, a = rgba[:,:,0], rgba[:,:,1], rgba[:,:,2], rgba[:,:,3]
a = np.asarray( a, dtype='float32' ) / 255.0
R, G, B = background
rgb[:,:,0] = r * a + (1.0 - a) * R
rgb[:,:,1] = g * a + (1.0 - a) * G
rgb[:,:,2] = b * a + (1.0 - a) * B
return np.asarray(rgb, dtype='uint8')
반응형
'Language > python' 카테고리의 다른 글
[python] SOLID principles (0) | 2024.02.23 |
---|---|
[python] 'dict' object has no attribute 'to_csv' (0) | 2024.02.13 |
[결측값 처리] fillna / backfill / bfill / pad / ffill (0) | 2024.02.05 |
[FastAPI] 3. 멀티프로세싱 (1) | 2023.12.06 |
[ Pytorch ] torch 기반의 모델 저장과 불러오기 (0) | 2023.08.15 |