<jupyter_start><jupyter_text>CNNSaket TiwariDate: 26 Jul 2019<jupyter_code>#flat karne se some information humlog loose kar rhe h
#imagesize- filter size + 1= no of iterations
#filter apply karne ko convolve karna bolte h
#convolve karne se we are preserving(capturing) special features of matrix.

#neural network lagane se pehle humlog filter laga lenge
#convolution ke wagah  neural network me kai saare features jaaynge like ek neuron horizontal line store karega, ev curves,ek vertical line,ek color 
#depending on the weight of filters , we will extract different features
#humlog neural network lagane se pehle filters ko laga ke, features ko update
#to humlog feature images k basis par prediction karenge
# dimension of the matrix after filter is applied: (row -row_filter +1)x(column -column_filter +1)
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
! pip install opencv-python
import cv2
im=cv2.imread('Assignments/Self/Images/landscape.jpg')
img = cv2.cvtColor( im, cv2.COLOR_BGR2GRAY)
print(img.shape)
plt.imshow(img, cmap='gray')
#plt.show
#Filter

# K =np.array([
#     [0,-4,0],
#     [-1,4,-1],
#     [0,-1,0]])

# print(K.shape)


#Horixontal-linedetection filter () Sobel filter
# K =np.array([
#     [-1,-2,-1],
#     [0,0,0],
#     [1,2,1]])

#Vertical
# K =np.array([
#    [-1,0,1],
#     [-2,0,2],
#     [-1,0,1]])

#Sharpen
# K =np.array([
#    [0,-1,0],
#     [-1,5,-1],
#     [0,-1,0]])

#Blur
K =np.array([
   [.1,.1,.1],
    [.1,.1,.1],
    [.1,.1,.1]])
out_r= img.shape[0]- K.shape[0]+1
out_c= img.shape[1] - K.shape[0] +1

new_img= np.zeros((out_r,out_c))
print(new_img.shape)
for r in range(out_r):
    for c in range(out_c):
        image_patch=img[ r: r+K.shape[0], c:c+K.shape[1]]
        prod= image_patch* K
        prod=prod.sum()
        new_img[r,c] = prod if prod > 0 else 0
plt.imshow(new_img)<jupyter_output><empty_output>