1

I want to implement Mean and Gaussian filtering. I implement the Median,but now I am lost while trying to calculate the average/mean and Gaussians.

I need help to do it manually, since using the libraries results pretty much easier but the task is to do it manually.

enter code here
#Import functions from OpenCV
import cv2

if __name__ == '__main__':
    ini = cv2.imread("img3.png",0) # Load an image
    final = ini[:]
    for y in range(len(ini)):
        for x in range(y):
            final[y,x]=ini[y,x]

 # create a sliding window of size 9
    pix=[ini[0,0]]*9
    for y in range(1,ini.shape[0]-1):
        for x in range(1,ini.shape[1]-1):

            #Pick up window element
            pix[0] = ini[y-1,x-1]
            pix[1] = ini[y,x-1]
            pix[2] = ini[y+1,x-1]
            pix[3] = ini[y-1,x]
            pix[4] = ini[y,x]
            pix[5] = ini[y+1,x]
            pix[6] = ini[y-1,x+1]
            pix[7] = ini[y,x+1]
            pix[8] = ini[y+1,x+1]

            pix.sort()#sort the window to find median
            final[y,x]=pix[4]#assign the median to centered element of the matrix

    cv2.imshow('Final_Picture', final) #Show the image
    cv2.waitKey()
Kathya
  • 11
  • 2

0 Answers0