Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam-dev-maker committed Sep 5, 2020
1 parent 04c31be commit 51293ad
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 46 deletions.
Binary file modified 1.Image_Rotation/Rotated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions 1.Image_Rotation/image_rotation_bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from PIL import Image
import numpy as np
import math

def floating_point(number):
temp=int(number)
if number>temp:
return round(temp+1)
else :
return round(temp)

def mat_Multi(angle,x,y,k):
tangent=math.tan(angle/2)
if k==0 or k==2:
X=x-y*tangent
Y=y
else:
X=x
Y=x*math.sin(angle)+y
return round(X),round(Y)

def rot(image,angle):
# Define the most occuring variables
angle=math.radians(angle)
cosine=math.cos(angle)
sine=math.sin(angle)

# Define the height and width of the new image that is to be formed
new_width = floating_point(abs(image.shape[0]*cosine)+abs(image.shape[1]*sine))
new_height = floating_point(abs(image.shape[1]*cosine)+abs(image.shape[0]*sine))

image1=np.zeros((floating_point(new_width),floating_point(new_height),image.shape[2]))

# Find the centre of the image about which we have to rotate the image
centre_row = round(((image.shape[0]+1)/2)-1) #with respect to the original image
centre_column= round(((image.shape[1]+1)/2)-1) #with respect to the original image

centre_height= round(((new_height+1)/2)-1) #with respect to the new image
centre_width= round(((new_width+1)/2)-1) #with respect to the new image

# Now let's traverse through the image matrix
for i in range(image.shape[0]):
for j in range(image.shape[1]):
y=image.shape[0]-1-i-centre_row
x=image.shape[1]-1-j-centre_column
X=round(x*cosine+y*sine)
Y=round(-x*sine+y*cosine)
X=centre_height-X
Y=centre_width-Y

if X<image1.shape[1] and Y<image1.shape[0] and X>=0 and Y>=0:
image1[Y,X,:]=image[i,j,:]
for i in range(image1.shape[0]):
prev = [image1[i][0][0], image1[i][0][1], image1[i][0][2], image1[i][0][3]]
for j in range(image1.shape[1]-1):
if (not any(image1[i][j][:])):
if (any(image1[i][j+1][:])):
image1[i][j][:] = prev
else:
prev = image1[i][j][:]
return image1


file_name=input("Enter the name of the file:- ")
im = np.array(Image.open(file_name))
rotation_angle=int(input("Enter the no. of turns in clockwise direction(by 90 degree) :- "))
im_copy=rot(im,rotation_angle)
pil_img=Image.fromarray((im_copy).astype(np.uint8))
pil_img.save("rotated_with_bound.png")
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
import numpy as np
import math


# def rot_perfect_angles(image1,turns):
# if turns==0:
# return image1
# else :
# image=np.zeros((image1.shape[1],image1.shape[0],image1.shape[2]))
# for j in range(image1.shape[0]):
# for i in range(image1.shape[1]):
# image[i,j,:] = image1[j,i,:]
# return rot(image[::-1],turns-1)


def floating_point(number):
temp=int(number)
if number>temp:
Expand All @@ -32,27 +20,16 @@ def mat_Multi(angle,x,y,k):
return round(X),round(Y)

def rot(image,angle):

# Define the most occuring variables
angle=math.radians(angle)
cosine=math.cos(angle)
sine=math.sin(angle)

image1=np.zeros_like(image)

# Define the height and width of the new image that is to be formed
# new_height = floating_point(abs(image.shape[0]*cosine)+abs(image.shape[1]*sine))
# new_width = floating_point(abs(image.shape[1]*cosine)+abs(image.shape[0]*sine))

# image1=np.zeros((new_width,new_height,image.shape[2]))

# Find the centre of the image about which we have to rotate the image
centre_row = round(((image.shape[0]+1)/2)-1)
centre_column= round(((image.shape[1]+1)/2)-1)

# centre_height= round(((new_height+1)/2)-1)
# centre_width= round(((new_width+1)/2)-1)

# Now let's traverse through the image matrix
for i in range(image.shape[0]):
for j in range(image.shape[1]):
y=image.shape[0]-1-i-centre_row
Expand All @@ -63,16 +40,23 @@ def rot(image,angle):
Y=centre_row-Y
if X<image1.shape[1] and Y<image1.shape[0] and X>=0 and Y>=0:
image1[Y,X,:]=image[i,j,:]
for i in range(image1.shape[0]):
prev = [image1[i][0][0], image1[i][0][1], image1[i][0][2], image1[i][0][3]]
for j in range(image1.shape[1]-1):
if (not any(image1[i][j][:])):
if (any(image1[i][j+1][:])):
image1[i][j][:] = prev
else:
prev = image1[i][j][:]
return image1





file_name="rotate.png"
file_name=input("Enter the name of the file:- ")
im = np.array(Image.open(file_name))
#rotation_angle=int(input("Enter the no. of turns in clockwise direction(by 90 degree) :- "))
im_copy=rot(im,80)
rotation_angle=float(input("Enter the no. of turns in clockwise direction(by 90 degree) :- "))
im_copy=rot(im,rotation_angle)
pil_img=Image.fromarray((im_copy).astype(np.uint8))
pil_img.save("Rotated.png")

pil_img.save("rotated_without_bound.png")
Binary file added 1.Image_Rotation/rotated_with_bound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1.Image_Rotation/rotated_without_bound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions 2.Applying_Kernels/blurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def convolve3d(image, kernel):

box_blur=np.array([[1,1,1],
[1,1,1],
[1,1,1]])
file_name="test_blur.jpg"
[1,1,1]])/9
file_name="test_sharpen.png"
im = np.array(Image.open(file_name))
pil_img=Image.fromarray(convolve3d(im, gaussian_blurr))
pil_img.save('result_blur.jpg')
pil_img=Image.fromarray(convolve3d(im, box_blur))
pil_img.save('result_box_blur.png')


Binary file removed 2.Applying_Kernels/result_blur.jpg
Binary file not shown.
Binary file added 2.Applying_Kernels/result_blur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2.Applying_Kernels/result_box_blur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions 2.Applying_Kernels/sharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ def convolve3d(image, kernel):
output[:,:,3]=image[:,:,3]
return output

Sharpen1=np.array([[-1, -1, -1, -1, -1],
[-1, 2, 2, 2, -1],
[-1, 2, 8, 2, -1],
[-1, 2, 2, 2, -1],
[-1, -1, -1, -1, -1]])

Sharpen=np.array([[-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1],[-1,-1,25,-1,-1],[-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1]])/-25

Sharpen=np.array([[-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1],
[-1,-1,25,-1,-1],
[-1,-1,-1,-1,-1],
[-1,-1,-1,-1,-1]])/-25

file_name="test_sharpen.png"
im = np.array(Image.open(file_name))
im=convolve3d(im,Sharpen)
Expand Down
7 changes: 0 additions & 7 deletions 3.Edge_Detection/canny.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,17 @@ def non_max_suppression(img,D):
return Z

def threshold(img, weak,strong,lowThresholdRatio=0.05, highThresholdRatio=0.09):

highThreshold = img.max() * highThresholdRatio
lowThreshold = highThreshold * lowThresholdRatio

M, N = img.shape
res = np.zeros((M,N), dtype=np.int32)

weak = np.int32(weak)
strong = np.int32(strong)

strong_i, strong_j = np.where(img >= highThreshold)
zeros_i, zeros_j = np.where(img < lowThreshold)

weak_i, weak_j = np.where((img <= highThreshold) & (img >= lowThreshold))

res[strong_i, strong_j] = strong
res[weak_i, weak_j] = weak

return res

def hysteresis(img, weak, strong):
Expand Down

0 comments on commit 51293ad

Please sign in to comment.