본문 바로가기

인공지능

머신러닝 이미지 LUT (LOOK UP TABLE) 처리

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
반응형