Search code examples
pythonimageopencvsmoothing

nine point smooth in OpenCV


How can i apply nine point smooth using OpenCV?

Info : Nine point smooth will take a 3x3 square of 9 pixels each and determine the count of each pixel.The counts per pixel are then averaged, and that value is assigned to the central pixel.

Nine Point Smooth : http://www.people.vcu.edu/~mhcrosthwait/clrs322/2DFilteringconcepts.htm


Solution

  • From the docs mentioned in the comments: https://docs.opencv.org/3.1.0/d4/d13/tutorial_py_filtering.html. It would be:

    import cv2
    import numpy as np
    
    img = cv2.imread('opencv_logo.png')
    
    blur = cv2.blur(img,(3,3))
    

    Or slightly more manually:

    kernel = np.ones((3,3), np.float32)/9
    dst = cv2.filter2D(img,-1,kernel)