Skip to content

Commit

Permalink
Image_Rotation_updated
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam-dev-maker committed Sep 3, 2020
1 parent 942769e commit 159e978
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
24 changes: 13 additions & 11 deletions 2.Applying_Kernels/blurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import numpy as np

def convolve3d(image, kernel):
kernel = np.flipud(np.fliplr(kernel))
threshold=200
#kernel = np.flipud(np.fliplr(kernel))
output = np.zeros_like(image)
image_padded = np.zeros((image.shape[0]+4,image.shape[1] + 4,image.shape[2]))
image_padded[3:-1:,3:-1:,:] = image
image_padded[0,0,:]=image[0,0,:]
image_padded[-1,-1,:]=image[-1,-1,:]
for x in range(image.shape[1]):
for y in range(image.shape[0]):
for z in range(image.shape[2]):
output[y, x,z]=(kernel * image_padded[y: y+5, x: x+5,z]).sum()
output[y,x,z]=(kernel * image_padded[y: y+5, x: x+5,z]).sum()
return output

gaussian_blurr=np.array([[1, 4, 6, 4, 1],
Expand All @@ -21,17 +24,16 @@ def convolve3d(image, kernel):
box_blur=np.array([[1,1,1],
[1,1,1],
[1,1,1]])
Sharpen=np.array([[0 ,-1, 0],
[-1, 5,-1],
[0 ,-1, 0]])
Edge=np.array([[-1 ,-1, -1],
[-1, 8,-1],
[-1 ,-1, -1]])
# Sharpen=np.array([[0 ,-1, 0],
# [-1, 5,-1],
# [0 ,-1, 0]])
# Edge=np.array([[-1 ,-1, -1],
# [-1, 8,-1],
# [-1 ,-1, -1]])
#file_name=input("Enter the name of the image to blurr:- ")
file_name="blur.jpg"
file_name="test_blur.jpg"
im = np.array(Image.open(file_name))
pil_img=Image.fromarray(convolve3d(im, gaussian_blurr/256))
pil_img.save('gaussian-blurr.jpg')
#print(im)
pil_img.save('result_blur.jpg')


File renamed without changes
Binary file added 2.Applying_Kernels/result_sharpen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 19 additions & 13 deletions 2.Applying_Kernels/sharpen.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
from PIL import Image
import numpy as np

def convolve3d(image, kernel):
threshold=100
kernel = np.flipud(np.fliplr(kernel))
output = np.zeros_like(image)
image_padded = np.zeros((image.shape[0]+2,image.shape[1] + 2,image.shape[2]))
image_padded[1:-1:,1:-1:,:] = image
image_padded[0,0,:]=image[0,0,:]
image_padded[-1,-1,:]=image[-1,-1,:]
for x in range(image.shape[1]):
for y in range(image.shape[0]):
for z in range(image.shape[2]):
output[y, x,z]=(kernel * image_padded[y: y+3, x: x+3,z]).sum()
summation=(kernel * image_padded[y: y+3, x: x+3,z]).sum()
if summation<threshold :
output[y, x,z]=50
else:
output[y, x,z]=summation
output[:,:,3]=image[:,:,3]
return output


Sharpen=np.array([[0 ,-1, 0],
[-1, 5,-1],
[0 ,-1, 0]])
Edge=np.array([[-1 ,-1, -1],
[-1, 8,-1],
Sharpen=np.array([[-1,-1, -1],
[-1, 9,-1],
[-1 ,-1, -1]])
#file_name=input("Enter the name of the image to blurr:- ")
file_name="sharpening.png"
# Edge=np.array([ [0 ,-1, 0],
# [-1, 4,-1],
# [0 ,-1, 0]])

file_name="test_sharpen.png"
im = np.array(Image.open(file_name))
pil_img=Image.fromarray(convolve3d(im, Sharpen))
pil_img.save('sharpened.png')
print(im.shape)
#print(im)
pil_img=Image.fromarray(convolve3d(im,Sharpen*0.9))
pil_img.save('result_sharpen.png')



Binary file removed 2.Applying_Kernels/sharpened.png
Binary file not shown.
File renamed without changes
File renamed without changes

0 comments on commit 159e978

Please sign in to comment.