python - Spatial filtering to image algorithm doesn't work -


i'm trying make spatial filtering algorithm python numpy. code below works predicted. output image not want.

import matplotlib.pyplot plt import scipy.misc misc import numpy np  class image:      def __init__(self, img):         self.img = img      # convolute     def convolution(self, h, w, kernel):         height_length = int(kernel.shape[0]/2)         width_length = int(kernel.shape[1]/2)          target_area = self.img[h-height_length : h+height_length+1, w-width_length : w+width_length+1]         r,g,b = target_area[...,0], target_area[...,1], target_area[...,2]         return (np.sum(r*kernel), np.sum(g*kernel), np.sum(b*kernel))      # stride     def stride(self, kernel):         height_length = int(kernel.shape[0]/2)         width_length = int(kernel.shape[1]/2)         new_img = []         h in range(height_length, self.img.shape[0]-height_length):             columns = np.empty([0,3], float)             w in range(width_length, self.img.shape[1]-width_length):                 columns = np.vstack([columns, np.asarray([self.convolution(h,w,kernel)])])              new_img.append(columns)          return np.asarray(new_img)   raccoon = misc.face()                 img = image(raccoon) test = img.stride(np.asarray([[1/9,1/9,1/9],[1/9,1/9,1/9],[1/9,1/9,1/9]])) plt.imshow(test) 

the code above shows following image.

enter image description here

in prediction, average filtering kernel makes source image blur. makes noise. adjust convolution r, g, b layers. there wrong point code or thinking? hope solution. thanks.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -