add function "adjust_contrast" in the function callback for better image displaying.
This commit is contained in:
@@ -23,7 +23,7 @@ from tritonclient.utils import np_to_triton_dtype
|
||||
from app.core.config import *
|
||||
from app.schemas.generate_image import GenerateImageModel
|
||||
from app.service.generate_image.utils.upload_sd_image import upload_png_sd
|
||||
|
||||
from app.service.generate_image.utils.adjust_contrast import adjust_contrast
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ class GenerateImage:
|
||||
self.redis_client.set(self.tasks_id, json.dumps(self.generate_data))
|
||||
else:
|
||||
image_result = result.as_numpy("generated_image")[0]
|
||||
image_result = adjust_contrast(image_result)
|
||||
image_url = upload_png_sd(image_result, user_id=self.user_id, category=f"{self.category}", object_name=f"{self.tasks_id}.png")
|
||||
self.generate_data['status'] = "SUCCESS"
|
||||
self.generate_data['message'] = "success"
|
||||
|
||||
31
app/service/generate_image/utils/adjust_contrast.py
Normal file
31
app/service/generate_image/utils/adjust_contrast.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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