Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
omocomo opened this issue Jun 3, 2022 · 0 comments
Open

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

omocomo opened this issue Jun 3, 2022 · 0 comments
Assignees
Labels
⭐ new feature New feature or request

Comments

@omocomo
Copy link
Member

omocomo commented Jun 3, 2022

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)
@omocomo omocomo added the ⭐ new feature New feature or request label Jun 3, 2022
@omocomo omocomo self-assigned this Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ new feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant