feat 新增对比度
This commit is contained in:
30
app/service/generate_image/utils/adjust_contrast.py
Normal file
30
app/service/generate_image/utils/adjust_contrast.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import cv2
|
||||
|
||||
|
||||
def adjust_contrast(image, alpha=1.5, beta=-60):
|
||||
"""
|
||||
调整图像的对比度和亮度。
|
||||
参数:
|
||||
image_path (numpy): 图像的路径。
|
||||
alpha (float): 控制对比度的系数。alpha > 1 增加对比度,alpha < 1 减少对比度。
|
||||
beta (int): 用于调整亮度的值,可以是正或负。
|
||||
返回:
|
||||
adjusted_image (ndarray): 调整对比度后的图像。
|
||||
"""
|
||||
|
||||
adjusted_image = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)
|
||||
return adjusted_image
|
||||
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
image = cv2.imread('output_6.png') # 替换为你的图片路径
|
||||
img_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
|
||||
alpha = 1.5 # 对比度系数,大于1增加对比度
|
||||
beta = -60 # 亮度调整,这里设置为0,不改变亮度
|
||||
|
||||
# 调整图像对比度
|
||||
result_image = adjust_contrast(image, alpha, beta)
|
||||
# 可以选择保存调整后的图像
|
||||
cv2.imwrite('adjusted_image.jpg', result_image) # 保存调整后的图片
|
||||
Reference in New Issue
Block a user