From fc765a85e5de17a29e4339f888e2497408776824 Mon Sep 17 00:00:00 2001 From: Sudipto Mallick <> Date: Tue, 9 Jan 2024 15:16:07 +0530 Subject: Implement Image filtering in DIP --- opencv/code/filter.py | 21 +++++++++++++++++++++ opencv/images/landscape.png | Bin 0 -> 1354640 bytes 2 files changed, 21 insertions(+) create mode 100644 opencv/code/filter.py create mode 100644 opencv/images/landscape.png (limited to 'opencv') diff --git a/opencv/code/filter.py b/opencv/code/filter.py new file mode 100644 index 0000000..ed80fb7 --- /dev/null +++ b/opencv/code/filter.py @@ -0,0 +1,21 @@ +import cv2 +import numpy as np +from matplotlib import pyplot as plt +from PIL import Image, ImageFilter +img=cv2.imread("images/landscape.png") +img1=Image.open("images/landscape.png") +mean=cv2.blur(img,(3,3)) +median=cv2.medianBlur(img,3) +w=cv2.filter2D(img,-1,3) +gau=cv2.GaussianBlur(img,(3,3),0) +minimg=np.array(img1.filter(ImageFilter.MinFilter(size=3)).convert('RGB')) +maximg=np.array(img1.filter(ImageFilter.MaxFilter(size=3)).convert('RGB')) +titles=["Original Image","Mean Image","Weighted Avg Image","Median Image","Min Image","Max Image"] +images=[img,mean,median,w,minimg,maximg] +for i in range(6): + plt.subplot(2,3,i+1) + plt.imshow(images[i][:,:,::-1]) + plt.title(titles[i]) + plt.xticks([]) + plt.yticks([]) +plt.show() \ No newline at end of file diff --git a/opencv/images/landscape.png b/opencv/images/landscape.png new file mode 100644 index 0000000..6614b21 Binary files /dev/null and b/opencv/images/landscape.png differ -- cgit 1.4.1-2-gfad0