diff --git a/Pipfile b/Pipfile index 4dbf561844..cab3ece65a 100644 --- a/Pipfile +++ b/Pipfile @@ -24,7 +24,7 @@ types-toml = "==0.10.8.7" python-dotenv = "==1.0.0" requests = "==2.31.0" Pillow = ">=7.1.2" -opencv-python = "==4.8.1.78" +opencv-python = "==4.9.0.80" pyperclip = "==1.8.2" click = "==8.1.7" psycopg2-binary = "==2.9.9" diff --git a/Pipfile.lock b/Pipfile.lock index 0181b1cf85..1a325b39fd 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "85f4a4fb239674dd7734a62777545b4421364d3b2fd924a4d4999abf64d13465" + "sha256": "365a109d81942e39c911969118e6c907d45978eff734c71980e7495451478977" }, "pipfile-spec": 6, "requires": { @@ -893,17 +893,17 @@ }, "opencv-python": { "hashes": [ - "sha256:91d5f6f5209dc2635d496f6b8ca6573ecdad051a09e6b5de4c399b8e673c60da", - "sha256:9814beca408d3a0eca1bae7e3e5be68b07c17ecceb392b94170881216e09b319", - "sha256:a7aac3900fbacf55b551e7b53626c3dad4c71ce85643645c43e91fcb19045e47", - "sha256:b983197f97cfa6fcb74e1da1802c7497a6f94ed561aba6980f1f33123f904956", - "sha256:bc31f47e05447da8b3089faa0a07ffe80e114c91ce0b171e6424f9badbd1c5cd", - "sha256:c4c406bdb41eb21ea51b4e90dfbc989c002786c3f601c236a99c59a54670a394", - "sha256:cc7adbbcd1112877a39274106cb2752e04984bc01a031162952e97450d6117f6" + "sha256:1a9f0e6267de3a1a1db0c54213d022c7c8b5b9ca4b580e80bdc58516c922c9e1", + "sha256:3f16f08e02b2a2da44259c7cc712e779eff1dd8b55fdb0323e8cab09548086c0", + "sha256:71dfb9555ccccdd77305fc3dcca5897fbf0cf28b297c51ee55e079c065d812a3", + "sha256:7b34a52e9da36dda8c151c6394aed602e4b17fa041df0b9f5b93ae10b0fcca2a", + "sha256:7e5f7aa4486651a6ebfa8ed4b594b65bd2d2f41beeb4241a3e4b1b85acbbbadb", + "sha256:dcf000c36dd1651118a2462257e3a9e76db789a78432e1f303c7bac54f63ef6c", + "sha256:e4088cab82b66a3b37ffc452976b14a3c599269c247895ae9ceb4066d8188a57" ], "index": "pypi", "markers": "python_version >= '3.6'", - "version": "==4.8.1.78" + "version": "==4.9.0.80" }, "packaging": { "hashes": [ diff --git a/library/hatomap.py b/library/hatomap.py index 5478072ef1..db0864abc9 100644 --- a/library/hatomap.py +++ b/library/hatomap.py @@ -357,12 +357,26 @@ def get_image(self, bbox: WebMercatorPixelBBox) -> np.ndarray: if self.brightness != 1.0 or self.chroma != 1.0: img_hsv = cv2.cvtColor(layer_img, cv2.COLOR_BGR2HSV) - img_hsv[..., 1] = img_hsv[..., 1] * self.brightness - img_hsv[..., 2] = img_hsv[..., 2] * self.chroma + img_hsv = img_hsv.astype(np.float32) # HSV値をfloatに変換 + + # 中間変数を使用(self.brightness と self.chroma を直接使用) + hsv_1 = img_hsv[..., 1] * self.brightness + hsv_2 = img_hsv[..., 2] * self.chroma + + # 型アサーションを追加 + assert hsv_1.dtype == np.float32 and hsv_2.dtype == np.float32 + + img_hsv[..., 1] = np.clip(hsv_1, 0, 255) + img_hsv[..., 2] = np.clip(hsv_2, 0, 255) + img_hsv = img_hsv.astype(np.uint8) # HSV値を元の型に戻す layer_img = cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR) if self.opacity != 1.0: - layer_img[layer_img[..., 3] != 0, 3] = int(round(self.opacity * 256)) + layer_img = layer_img.astype(np.float32) # HSV値をfloatに変換 + layer_img[layer_img[..., 3] != 0, 3] = np.clip( + layer_img[layer_img[..., 3] != 0, 3] * self.opacity * 256, 0, 255 + ) + layer_img = layer_img.astype(np.uint8) # 画像を元の型に戻す return layer_img