Last active
June 14, 2024 08:39
-
-
Save curegit/4c7b39727fa6b3416e2db1a18d4659d3 to your computer and use it in GitHub Desktop.
OpenCV でバイラテラルフィルタ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
def bilateral(i, o, d=7, sigmaColor=32, sigmaSpace=10): | |
img = cv2.imdecode(np.frombuffer(open(i, "rb").read(), np.uint8), cv2.IMREAD_COLOR | cv2.IMREAD_ANYDEPTH) | |
denoised = cv2.bilateralFilter(img, d=d, sigmaColor=sigmaColor, sigmaSpace=sigmaSpace) | |
ok, bin = cv2.imencode(".png", denoised, [cv2.IMWRITE_PNG_COMPRESSION, 9]) | |
assert ok | |
open(o, "wb").write(bin.tobytes()) | |
bilateral("input.png", "output.png", 7, 32, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment