In [95]:
from skimage import io, viewer, exposure
import numpy as np
import matplotlib.pyplot as plt
In [96]:
img = io.imread("image.jpg" ,as_grey= True)
In [97]:
img.shape
Out[97]:
In [98]:
print("Frist 5 columns of the image", img[:5,:5] * 255)
plt.imshow(img)
Out[98]:
In [99]:
def convolve2d(image, kernel):
kernel = np.flipud(np.fliplr(kernel))
output = np.zeros_like(image)
image_padded =np.zeros((image.shape[0] + 2, image.shape[1] + 2))
image_padded[1:-1, 1:-1]= image
for x in range(image.shape[1]):
for y in range(image.shape[0]):
output[y,x] = (kernel * image_padded[y:y+3,x:x+3]).sum()
print("new Shape")
print(output.shape)
return output
In [100]:
image_equalized = exposure.equalize_adapthist(img/np.max(np.abs(img)), clip_limit=0.03)
plt.imshow(image_equalized, cmap = plt.cm.gray)
Out[100]:
In [101]:
sharp_kernel = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]])
edge_kernel = np.array([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]])
gaussian_kernel = (1/16) * np.array([[1,2,1],[2,4,2],[1,2,1]])
In [102]:
image_sharpen = convolve2d(img, sharp_kernel)
image_edge = convolve2d(img, edge_kernel)
image_blurred= convolve2d(img, gaussian_kernel)
In [103]:
print("\ First columns and rows of the sharpen image", image_sharpen[:5,:5]*255)
print("\ First columns and rows of the edge image", image_edge[:5,:5]*255)
print("\ First columns and rows of the blured image", image_blurred[:5,:5]*255)
In [104]:
img_list = [image_sharpen, image_edge,image_blurred]
img_name= ["sharpen" , "edge", "Blurred"]
fig = plt.figure(figsize=(30,30))
for i in range(1,4):
fig.add_subplot(3,1, i)
plt.imshow(img_list[i-1] , interpolation="nearest", aspect ="auto", cmap=plt.cm.gray)
In [ ]:
In [ ]:
In [ ]:
In [ ]: