Last active
June 14, 2024 06:15
-
-
Save curegit/f284ff9fc0f25eb6ae728fff144193be to your computer and use it in GitHub Desktop.
OpenCV で Non-local Means フィルタ
This file contains 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 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