boostcampaitech3 / final-project-level3-cv-17

[2022.05.16 ~ 2022.06.10] 🌤️미세먼지 없는 맑은 사진📷 - 부스트캠프 AI Tech 3기 최종 프로젝트
13 stars 3 forks source link

[Sky Replacement] 그라데이션 이용해 개선하기 #29

Open omocomo opened 2 years ago

omocomo commented 2 years ago

Background

하늘과 이미지 경계를 그라데이션을 이용해 자연스럽게 연결되도록 한다.

Content

gray_gradient_v5

Details

그라데이션 이미지 만들기 참고

import numpy as np
def get_gradient_3d(width, height, start_list, stop_list, is_horizontal_list):
    result = np.zeros((height, width, len(start_list)), dtype=np.float)
    for i, (start, stop, is_horizontal) in enumerate(zip(start_list, stop_list, is_horizontal_list)):
        result[:, :, i] = get_gradient_2d(start, stop, width, height, is_horizontal)
    return result

def get_gradient_2d(start, stop, width, height, is_horizontal):
    if is_horizontal:
        return np.tile(np.linspace(start, stop, width), (height, 1))
    else:
        return np.tile(np.linspace(start, stop, height), (width, 1)).T

array = get_gradient_3d(512, 256, (0, 0, 0), (200, 200, 200), (False, False, False))
Image.fromarray(np.uint8(array)).save('C:/Users/Downloads/gray_gradient_v5.jpg', quality=95)

custom 예시

array1 = get_gradient_3d(512, 96, (0, 0, 0), (95, 95, 95), (False, False, False))
array2 = get_gradient_3d(512, 64, (95, 95, 95), (95, 95, 95), (False, False, False))
array3 = get_gradient_3d(512, 96, (95, 95, 95), (200, 200, 200), (False, False, False))
array = np.concatenate((array1, array2, array3), axis=0)
Image.fromarray(np.uint8(array)).save('C:/Users/Downloads/gray_gradient_v7.jpg', quality=100)

이미지에 적용 참고

src1 = np.array(Image.open('C:/Users/omocomo/Downloads/origin.jpg'))
src2 = np.array(Image.open('C:/Users/omocomo/Downloads/dehazed_cloud_image (23).jpg').resize(src1.shape[1::-1], Image.BILINEAR))
mask1 = np.array(Image.open('C:/Users/omocomo/Downloads/gray_gradient_v.jpg').resize(src1.shape[1::-1], Image.BILINEAR))
mask1 = mask1 / 255
dst = src1 * mask1 + src2 * (1 - mask1)