Skip to content

Instantly share code, notes, and snippets.

@curegit
Last active June 14, 2024 06:15
Show Gist options
  • Save curegit/f284ff9fc0f25eb6ae728fff144193be to your computer and use it in GitHub Desktop.
Save curegit/f284ff9fc0f25eb6ae728fff144193be to your computer and use it in GitHub Desktop.
OpenCV で Non-local Means フィルタ
import cv2
import numpy as np
def nlmeans(i, o, h=10, hColor=10, templateWindowSize=9, searchWindowSize=27):
img = cv2.imdecode(np.frombuffer(open(i, "rb").read(), np.uint8), cv2.IMREAD_COLOR | cv2.IMREAD_ANYDEPTH)
denoised = cv2.fastNlMeansDenoisingColored(img, h=h, hColor=hColor, templateWindowSize=templateWindowSize, searchWindowSize=searchWindowSize)
ok, bin = cv2.imencode(".png", denoised, [cv2.IMWRITE_PNG_COMPRESSION, 9])
assert ok
open(o, "wb").write(bin.tobytes())
nlmeans("input.png", "output.png", 10, 10, 9, 27)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment