Created
July 14, 2016 06:38
-
-
Save akkijp/fd62cccd3774bd42b15fcbf7583ae8d5 to your computer and use it in GitHub Desktop.
ガウシアンフィルタ
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
#! /usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import cv2 | |
import numpy as np | |
src = cv2.imread("./Lenna.bmp", -1) | |
dst = np.zeros_like(src) | |
def pickup_pixel(img, x, y): | |
row_len, cal_len = src.shape | |
if x < 0: | |
x = 0 | |
if y < 0: | |
y = 0 | |
if x > row_len-1: | |
x = row_len-1 | |
if y > cal_len-1: | |
y = cal_len-1 | |
return img[x, y] | |
row_len, cal_len = src.shape | |
g_filter = [ | |
[1.0/256, 4.0/256, 6.0/256, 4.0/256, 1.0/246], | |
[4.0/256, 16.0/256, 24.0/256, 16.0/256, 4.0/246], | |
[6.0/256, 24.0/256, 36.0/256, 24.0/256, 6.0/246], | |
[4.0/256, 16.0/256, 24.0/256, 16.0/256, 4.0/246], | |
[1.0/256, 4.0/256, 6.0/256, 4.0/256, 1.0/246], | |
] | |
print(row_len, cal_len) | |
print(g_filter) | |
for x in range(row_len): | |
for y in range(cal_len): | |
dst_pixel = 0.0 | |
for n in range(5): | |
for m in range(5): | |
pixel = pickup_pixel(src, x+n-2, y+m-2) | |
dst_pixel = dst_pixel + pixel*g_filter[n][m] | |
dst[x, y] = int(dst_pixel) | |
cv2.imshow("result", dst) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment