ArchGuass - S04.Ipynb - Colab
ArchGuass - S04.Ipynb - Colab
1. Guassian Filter
import numpy as np
import cv2
import matplotlib.pyplot as plt
def show(img):
plt.axis('off')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
# Read an Image
image = cv2.imread("img.jpg")
guass_img = add_gaussian_noise(image)
show(guass_img)
# Direct way
guass = cv2.GaussianBlur(guass_img,(7,7),cv2.BORDER_DEFAULT)
show(guass)
for i in range(height):
for j in range(width):
# Extract the region corresponding to the kernel size
region = padded_image[i:i + k_size, j:j + k_size]
new_image[i, j] = np.sum(region * kernel)
return new_image
plt.imshow(grayed,cmap="gray")
<matplotlib.image.AxesImage at 0x1b3dc5e6990>
plt.imshow(filtered_image,cmap="gray")
<matplotlib.image.AxesImage at 0x1b3dc660f50>
Image shapes
(201, 251, 3)
(166, 194, 3)
(194, 259, 3)
import numpy as np
import cv2
# Number of images
N = float(len(image_filenames))
# 1. Read the first image to get dimensions and initialize the output array
first_image = cv2.imread(image_filenames[0], cv2.IMREAD_GRAYSCALE)
height, width = first_image.shape
output = np.zeros((height, width), dtype=np.float32)
# 2. Loop through each image, read it, and add to the output
for image_filename in image_filenames:
# Read the image
image = cv2.imread(image_filename, cv2.IMREAD_GRAYSCALE)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[62], line 22
20 # Ensure the image is the correct size
21 if image.shape != (height, width):
---> 22 raise ValueError(f"Image {image_filename} does not have the correct
dimensions.")
24 # Add the image to the output
25 output += image / N # Average it by dividing by N