Untitled

 avatar
unknown
python
a year ago
952 B
3
Indexable
import numpy as np
import cv2
import matplotlib.pyplot as plt


image = cv2.imread('Miller_Range,_Antarctica_-_Meteorite_(2).jpg')
image = image[1000:2500, 1000:2000]



kernel = np.ones((25, 25)) / 625
#set
image_height, image_width, num_channels = image.shape
kernel_height, kernel_width = kernel.shape

#create padding to deal with edges
pad_height = kernel_height // 2
pad_width = kernel_width // 2
padded_image = np.pad(image, ((pad_height, pad_height), (pad_width, pad_width), (0, 0)), mode='constant')


blurred_image = np.zeros_like(image)

for y in range(image_height):
    for x in range(image_width):
        for c in range(num_channels):
            region = padded_image[y:y+kernel_height, x:x+kernel_width, c]
            blurred_image[y, x, c] = np.sum(region * kernel)
blurred_image = np.clip(blurred_image, 0, 255).astype(np.uint8)


plt.imshow(blurred_image)

plt.axis('off')
plt.show()


plt.imshow(image)
plt.axis('off')
plt.show()
Editor is loading...
Leave a Comment