@@ -135,9 +135,23 @@ def and_operation(self,img_matrix1,img_matrix2):
135135 new_matrix [i ][j ]= int (img_matrix1 [i ][j ]) & int (img_matrix2 [i ][j ])
136136 return new_matrix
137137
138- def convolution (self ,img_matrix ,convolution_matrix ):
139- """That function take the matrix of image and convolution"""
140- pass
138+ def convolution (self ,img_matrix ,kernel ):
139+ """That function take the matrix of image and convolution
140+ The principe of convolution is to make translation of convolution matrix
141+ on the img matrix, at each time, the center of submatrix take the sum of all values multiplity
142+ of arround pixel with the convolution matrix
143+ @img_matrix must be an numpy array
144+ @kernel matrix must be an numpy array"""
145+
146+ dimension = img_matrix .shape
147+ new_img_matrix = np .zeros (dimension )
148+ #We need to know were will be the center of convolution
149+ #now we will consider only 3*3 convolution matrix
150+ for i in range (1 ,dimension [0 ]- 1 ):
151+ for j in range (1 ,dimension [1 ]- 1 ):
152+ p_pixel = img_matrix [i - 1 ][j - 1 ]* kernel [0 ][0 ]+ img_matrix [i - 1 ,j ]* kernel [0 ][1 ]+ img_matrix [i - 1 ,j + 1 ]* kernel [0 ][2 ]+ img_matrix [i ,j - 1 ]* kernel [1 ][0 ]+ img_matrix [i ][j ]* kernel [1 ][1 ]+ img_matrix [i ][j + 1 ]* kernel [1 ,2 ]+ img_matrix [i + 1 ][j - 1 ]* kernel [2 ][0 ]+ img_matrix [i + 1 ][j ]* kernel [2 ][1 ]+ img_matrix [i + 1 ,j + 1 ]* kernel [2 ][2 ]
153+ new_img_matrix [i ][j ]= p_pixel
154+ return new_img_matrix
141155
142156 def get_delay (self ,pusblish_time ,current_time ):
143157 passed_time = current_time - pusblish_time
0 commit comments