Computer vision filter implemetation
Computer vision filter implemetation
Computer vision filter implemetation
Computer Vision
uploaded = files.upload()
# Salt mode
mask = np.random.rand(image.shape[0], image.shape[1]) <= s_p_ratio / 2
out[mask] = 255
# Pepper mode
mask = np.random.rand(image.shape[0], image.shape[1]) <= s_p_ratio / 2
out[mask] = 0
return out
#############################################
#############################################
#following Code is for Weighted Average Filter
#############################################
#############################################
#############################################
#############################################
#following Code is for Gaussian Filter
#############################################
#############################################
def gausian_kernel(size):
if size%2==0:
print('kernel size should be odd')
return
sigma = (size-1)/2
# [0,size]→[-sigma, sigma]Shift
x = y = np.arange(0,size) - sigma
X,Y = np.meshgrid(x,y)
print(sigma)
mat = gausian(X,Y,sigma)
g_fil_hand = gausian_kernel(3)
#Filter shape
#[[0.05854983 0.09653235 0.05854983]
#[0.09653235 0.15915494 0.09653235]
#[0.05854983 0.09653235 0.05854983]]
#############################################
#############################################
#following Code is for Median Filter
#############################################
#############################################
Figure 1 Salt & Pepper Noise Image Figure 2 Average Filtered image Figure 3 Weighted Average Filtered Image
Figure 4 Gaussian Filtered Image Figure 5 Median Filtered Image
Comparison
# depth = -1, means destination image has depth same as input image
avg_filtered_img = cv2.filter2D(G_noise_img, -1, avg_filter)
plot_im(avg_filtered_img, "avg filtered image")
Pruwit:
Sobel:
Comparison: