Skip to content Skip to sidebar Skip to footer

Python Laplace Filter Returns Wrong Values

As I need to implement a sort of image processing program in python I also wanted to implement the laplace filter. I used the matrix -1 -1 -1 -1 8 -1 -1 -1 -1 and implemented the

Solution 1:

You must not modify the array in place, i.e. if you are applying the filter to self._dataIn, then you must not store the result in self._dataIn because on the next filter operation, the input will not be the correct one.

By the way, it is easier to use numpy matrix multiplication to do the filtering (and to use a one component image):

img = img.mean(2) # get a NxM image
imgOut = np.zeros (img.shape, dtype = uint8)
M = np.array([
    [-1, -1, -1], 
    [-1,  8, -1], 
    [-1, -1, -1]
])
forrowinrange(1, img.shape[0] -1):
    for col inrange(1, img.shape[1] -1):
        value= M * img[(row-1):(row+2), (col -1):(col +2)]
        imgOut[row, col] =min(255, max(0, value.sum ()))

Result:

enter image description hereenter image description here

Post a Comment for "Python Laplace Filter Returns Wrong Values"