Project

General

Profile

Feature #904 » main.py

run this one - Muting LI , 12/21/2023 01:24 PM

 
1
import numpy as np
2
from PIL import Image
3
from image_processing import find_overlap
4
from gamma_correction import adjust_gamma_with_gradient
5

    
6
def gradient_gamma_correction_overlap(img1, img2, overlap_width, start_gamma=1.0, end_gamma=0.5):
7
    img1_overlap = img1.crop((img1.width - overlap_width, 0, img1.width, img1.height)).convert('RGB')
8
    img2_overlap = img2.crop((0, 0, overlap_width, img2.height)).convert('RGB')
9

    
10
    img1_overlap_corrected = adjust_gamma_with_gradient(np.array(img1_overlap), start_gamma, end_gamma)
11
    img2_overlap_corrected = adjust_gamma_with_gradient(np.array(img2_overlap), end_gamma, start_gamma)
12

    
13
    img1.paste(Image.fromarray(img1_overlap_corrected), (img1.width - overlap_width, 0))
14
    img2.paste(Image.fromarray(img2_overlap_corrected), (0, 0))
15

    
16
    return img1, img2
17

    
18
def main():
19
    image_left_path = 'ImageLeft0.png'  # Replace with your image path
20
    image_right_path = 'ImageRight0.png'  # Replace with your image path
21
    image_left = Image.open(image_left_path)
22
    image_right = Image.open(image_right_path)
23

    
24
    overlap_width = find_overlap(image_left, image_right)
25
    image_left_corrected, image_right_corrected = gradient_gamma_correction_overlap(
26
        image_left, image_right, overlap_width
27
    )
28

    
29
    image_left_corrected.save('imageleft1.png')
30
    image_right_corrected.save('imageright1.png')
31

    
32
if __name__ == "__main__":
33
    main()
(3-3/4)