728x90
반응형
현업에서 특정 픽셀에 따른 대비밝기 처리를해야하는데,
추후에 픽셀 받아서 처리하면될것같음.
import numpy as np
# 이미지에 LUT 적용하는 함수
def apply_lut(image, lut):
"""
이미지에 LUT(룩업 테이블)을 적용합니다.
:param image: 적용할 이미지
:param lut: LUT(룩업 테이블)
:return: LUT가 적용된 이미지
"""
# 이미지를 그레이스케일로 변환 (LUT는 그레이스케일 이미지에만 적용 가능)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# LUT 적용
result_image = cv2.LUT(gray_image, lut)
return result_image
# 테스트 이미지 경로
test_img_path = "dark.png"
# 테스트 이미지 로드 및 전처리
test_img = cv2.imread(test_img_path)
test_img_resized = cv2.resize(test_img, (128, 128))
# 예시: 대비 조절을 위한 LUT 생성
lut = np.zeros(256, dtype=np.uint8)
brightness_value = 50 # 예시로 50으로 설정
contrast_value = 50 # 예시로 50으로 설정
for i in range(256):
# 밝기 조절
lut[i] = np.clip(i + brightness_value, 0, 255)
# 대비 조절
if i <= contrast_value:
lut[i] = lut[i] * 7 # 대비를 2배로 증가시킵니다.
result_img = apply_lut(test_img_resized, lut)
# 결과 이미지 저장
result_img_path = "result_image_with_lut.jpg"
cv2.imwrite(result_img_path, result_img)
print("이미지에 LUT를 적용한 결과를 저장했습니다.")
728x90
반응형
'인공지능' 카테고리의 다른 글
넘파이(Numpy) (0) | 2024.05.08 |
---|---|
판다스(Pandas) (0) | 2024.05.07 |
YOLOv5 설치/기본제공모델/커스텀모델학습 (0) | 2024.05.07 |
라벨스튜디오 기본기 (AI 마킹 모델학습) (0) | 2024.05.02 |
딥러닝 꽃 카테고리 분류 CNN모델 (메모용) (0) | 2024.04.28 |