Spaces:
Sleeping
Sleeping
| import cv2 | |
| import numpy as np | |
| def adjust_image_tone(input_image, brightness, contrast, gamma): | |
| image1 = cv2.imread(input_image) | |
| image2 = cv2.cvtColor(image1, cv2.COLOR_BGR2HSV) | |
| image3 = image2.astype(np.float32) | |
| # 明るさとコントラストの調整(Vチャンネル) | |
| image3[:, :, 2] *= contrast / 50.0 + 1 | |
| image3[:, :, 2] += brightness - 50 | |
| # 値の範囲を0から255に制限 | |
| image3[:, :, 2] = np.clip(image3[:, :, 2], 0, 255) | |
| image4 = image3.astype(np.uint8) | |
| adjusted_image = cv2.cvtColor(image4, cv2.COLOR_HSV2RGB) | |
| return adjusted_image | |
| def adjust_image_tone(input_image, brightness, contrast, gamma): | |
| image = cv2.imread(input_image) | |
| # 明るさとコントラストの調整 | |
| alpha = (contrast + 127) / 127.0 | |
| adjusted = cv2.convertScaleAbs(image, alpha=alpha, beta=brightness - 127) | |
| return adjusted | |
| def adjust_image_tone(input_image, brightness, contrast, gamma): | |
| image = cv2.imread(input_image) | |
| return image | |
| input_image_path = r"C:\Users\jamad\Desktop\shop_image_cat.jpg" | |
| brightness_value = 10 # 明るさの調整値を設定してください | |
| contrast_value = 10 # コントラストの調整値を設定してください | |
| gamma_value = 1.5 # ガンマ値を設定してください | |
| adjusted = adjust_image_tone(input_image_path, brightness_value, contrast_value, gamma_value) | |
| # 調整された画像を表示 | |
| cv2.imshow("Adjusted Image", adjusted) | |
| cv2.waitKey(0) | |
| cv2.destroyAllWindows() | |