Skip to content

Instantly share code, notes, and snippets.

@curegit
Last active June 14, 2024 08:39
Show Gist options
  • Save curegit/4c7b39727fa6b3416e2db1a18d4659d3 to your computer and use it in GitHub Desktop.
Save curegit/4c7b39727fa6b3416e2db1a18d4659d3 to your computer and use it in GitHub Desktop.
OpenCV でバイラテラルフィルタ
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