I tried using some filters of OpenCV.
The environment is the environment created by here.
image_filter.py
#-*- coding:utf-8 -*-
import cv2
import numpy as np
def main():
#Read the input image
img = cv2.imread("input.jpg ")
#Grayscale conversion
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
cv2.imwrite("gray.jpg ", gray )
#median filter
median = cv2.medianBlur(gray,9)
cv2.imwrite("median.jpg ", median )
#sobel filter
gray_x = cv2.Sobel(gray, cv2.CV_32F, 1, 0, ksize=3)
gray_y = cv2.Sobel(gray, cv2.CV_32F, 0, 1, ksize=3)
sobel = np.sqrt(gray_x ** 2 + gray_y ** 2)
cv2.imwrite("sobel.jpg ", sobel)
#Gaussian filtering
gauss = cv2.GaussianBlur(gray, (11,11), 5.0)
cv2.imwrite("gauss.jpg ", gauss )
if __name__ == "__main__":
main()
Change ʻinput.jpg` to the image you want to play with
$ python image_filter.py
Execute and you're done.
I used this image for input.
gray.jpg
median.jpg
sobel.jpg
gauss.jpg
Recommended Posts