1
|
#!/usr/bin/env python
|
2
|
# -*- coding: utf-8 -*-
|
3
|
|
4
|
##
|
5
|
# @file image_processor.py
|
6
|
# @brief This script defines the ImageProcessor class, which uses the ImageBlender and GammaCorrector classes to adjust and blend images.
|
7
|
#
|
8
|
|
9
|
import cv2 as cv
|
10
|
from imageBlender import ImageBlender
|
11
|
from gammaCorrector import GammaCorrector
|
12
|
|
13
|
##
|
14
|
# @class ImageProcessor
|
15
|
# @brief A class for processing images using gamma correction and blending.
|
16
|
#
|
17
|
class ImageProcessor:
|
18
|
# ˅
|
19
|
|
20
|
# ˄
|
21
|
|
22
|
##
|
23
|
# @fn __init__(self, gamma, blend_ratio=0.21)
|
24
|
# @brief Constructor for ImageProcessor.
|
25
|
# @param gamma Gamma value for correction.
|
26
|
# @param blend_ratio Blend ratio for image blending, default is 0.21.
|
27
|
#
|
28
|
def __init__(self, gamma, blend_ratio=0.21):
|
29
|
# ˅
|
30
|
self.gamma_corrector = GammaCorrector(gamma)
|
31
|
self.image_blender = ImageBlender(self.gamma_corrector, blend_ratio)
|
32
|
# ˄
|
33
|
|
34
|
##
|
35
|
# @fn adjust_images(self, left_image_path, right_image_path)
|
36
|
# @brief Adjusts and blends two images.
|
37
|
# @param left_image_path Path to the left image.
|
38
|
# @param right_image_path Path to the right image.
|
39
|
# @return A tuple of adjusted left, adjusted right, and blended images.
|
40
|
#
|
41
|
def adjust_images(self, left_image_path, right_image_path):
|
42
|
# ˅
|
43
|
adjusted_left, adjusted_right, blended_image = self.image_blender.process_images(left_image_path, right_image_path)
|
44
|
return adjusted_left, adjusted_right, blended_image
|
45
|
# ˄
|
46
|
|
47
|
# Script-level code to demonstrate the use of ImageProcessor
|
48
|
# ...
|
49
|
|
50
|
left_image_path = 'Imageleft0.png'
|
51
|
right_image_path = 'Imageright0.png'
|
52
|
|
53
|
gamma_value = 1.05
|
54
|
processor = ImageProcessor(gamma_value)
|
55
|
|
56
|
adjusted_left, adjusted_right, blended_image = processor.adjust_images(left_image_path, right_image_path)
|
57
|
|
58
|
cv.imwrite('adjusted_left.jpg', adjusted_left)
|
59
|
cv.imwrite('adjusted_right.jpg', adjusted_right)
|
60
|
cv.imwrite('blended_image.jpg', blended_image)
|
61
|
|
62
|
cv.imshow('Adjusted Left Image', adjusted_left)
|
63
|
cv.imshow('Adjusted Right Image', adjusted_right)
|
64
|
cv.imshow('Blended Image', blended_image)
|
65
|
cv.waitKey(0)
|
66
|
cv.destroyAllWindows()
|