Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam-dev-maker committed Sep 6, 2020
1 parent bdd61d3 commit 0ba90ed
Show file tree
Hide file tree
Showing 21 changed files with 229 additions and 2 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file removed 1.Image_Rotation/Rotated.png
Binary file not shown.
2 changes: 1 addition & 1 deletion 1.Image_Rotation/image_rotation_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def rot(image,angle):

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) :- "))
rotation_angle=int(input("Enter the angle :- "))
im_copy=rot(im,rotation_angle)
pil_img=Image.fromarray((im_copy).astype(np.uint8))
pil_img.save("rotated_with_bound.png")
2 changes: 1 addition & 1 deletion 1.Image_Rotation/image_rotation_nobound.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def rot(image,angle):

file_name=input("Enter the name of the file:- ")
im = np.array(Image.open(file_name))
rotation_angle=float(input("Enter the no. of turns in clockwise direction(by 90 degree) :- "))
rotation_angle=float(input("Enter the angle :- "))
im_copy=rot(im,rotation_angle)
pil_img=Image.fromarray((im_copy).astype(np.uint8))
pil_img.save("rotated_without_bound.png")
76 changes: 76 additions & 0 deletions 1.Image_Rotation/image_shearing_bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from PIL import Image
import numpy as np
import math

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

def mat_Multi(angle,x,y,k):
tangent=math.tan(angle/2)
if k==2 or k==0:
X=x-y*tangent
Y=y
if k==1:
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]))
image2=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

for k in range(3):
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,Y=mat_Multi(angle,x,y,k)
if k==0:
X,Y=mat_Multi(angle,x,y,0)
elif k==1:
X,Y=mat_Multi(angle,x,y,0)
X,Y=mat_Multi(angle,X,Y,1)
elif k==2:
X,Y=mat_Multi(angle,x,y,0)
X,Y=mat_Multi(angle,X,Y,1)
X,Y=mat_Multi(angle,X,Y,2)
X=centre_height-X
Y=centre_width-Y
if X<image1.shape[1] and Y<image1.shape[0] and X>=0 and Y>=0:
if k==2:
image2[Y,X,:]=image[i,j,:]
else:
image1[Y,X,:]=image[i,j,:]

return image2





file_name="rotate.png"#input("Enter the name of the file:- ")
im = np.array(Image.open(file_name))
rotation_angle=-int(input("Enter the angle :- "))
im_copy=rot(im,rotation_angle)
pil_img=Image.fromarray((im_copy).astype(np.uint8))
pil_img.save("rotated_sheared_bound.png")
67 changes: 67 additions & 0 deletions 1.Image_Rotation/image_shearing_nobound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from PIL import Image
import numpy as np
import math

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

def mat_Multi(angle,x,y,k):
tangent=math.tan(angle/2)
if k==2 or k==0:
X=x-y*tangent
Y=y
if k==1:
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)
image1=np.zeros_like(image)
image2=np.zeros_like(image)

# 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)
for k in range(3):
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,Y=mat_Multi(angle,x,y,k)
if k==0:
X,Y=mat_Multi(angle,x,y,0)
elif k==1:
X,Y=mat_Multi(angle,x,y,0)
X,Y=mat_Multi(angle,X,Y,1)
elif k==2:
X,Y=mat_Multi(angle,x,y,0)
X,Y=mat_Multi(angle,X,Y,1)
X,Y=mat_Multi(angle,X,Y,2)
X=centre_column-X
Y=centre_row-Y
if X<image1.shape[1] and Y<image1.shape[0] and X>=0 and Y>=0:
if k==2:
image2[Y,X,:]=image[i,j,:]
else:
image1[Y,X,:]=image[i,j,:]
return image2





file_name="rotate.png"#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_sheared_without_bound.png")
Binary file added 1.Image_Rotation/rotated_sheared_bound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 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.
Binary file removed 3.Edge_Detection/result_morphology.jpg
Binary file not shown.
Binary file added 5.Masking/mask.jpeg
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 5.Masking/masked.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions 5.Masking/masking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import cv2
import numpy as np
from PIL import Image

def masking_image(image,lower,upper):
image = cv2.cvtColor(image.astype(np.uint8), cv2.COLOR_BGR2HSV)
image_copy=image
for x in range(image.shape[0]):
for y in range(image.shape[1]):
for z in range(image.shape[2]):
if image[x,y,z]>=lower[z] and image[x,y,z]<=upper[z]:
image[x,y,z]=360
else:
image[x,y,z]=0
image=~(image_copy ^ image)
image= cv2.cvtColor(image, cv2.COLOR_HSV2RGB)
return image


def convolve3d(image, kernel):
output = np.zeros_like(image)
image_padded = np.zeros((image.shape[0]+kernel.shape[0]-1,image.shape[1] + kernel.shape[1]-1,image.shape[2]))
image_padded[kernel.shape[0]-2:-1:,kernel.shape[1]-2:-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+kernel.shape[0], x: x+kernel.shape[1],z]).sum()
return output

gaussian_blurr=np.array([[1, 4, 6, 4, 1],
[4, 16, 24, 16, 4],
[6, 24, 36, 24, 6],
[4, 16, 24, 16, 4],
[1, 4, 6, 4, 1]])/256

file_name="mask.jpeg"
im = np.array(Image.open(file_name))
lower_blue = np.array([94,130,38])
upper_blue = np.array([179,255,255])
im=masking_image(convolve3d(im,gaussian_blurr),lower_blue,upper_blue)
pil_img=Image.fromarray(im.astype(np.uint8))
pil_img.save('masked.jpeg')
9 changes: 9 additions & 0 deletions OpenCV/blur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image

img = cv2.imread('test_kernel.png')
blur =cv2.GaussianBlur(img,(5,5),1)
pil_img=Image.fromarray(blur)
pil_img.save('gaussian_blur.png')
19 changes: 19 additions & 0 deletions OpenCV/canny_edge_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image

img = cv2.imread("edge-detection1.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
canny = cv2.Canny(img, 602, 452)

titles = ['image', 'canny']
images = [img, canny]
pil_img=Image.fromarray(canny).convert('RGB')
pil_img.save('result_canny.png')
for i in range(2):
plt.subplot(1, 2, i+1), plt.imshow(images[i], 'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])

plt.show()
Binary file added OpenCV/edge-detection1.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 OpenCV/gaussian_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 OpenCV/result_canny.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 OpenCV/result_sobel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions OpenCV/sobel_edge_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import cv2
import numpy as np
from PIL import Image

img = cv2.imread('edge-detection1.png', cv2.IMREAD_GRAYSCALE)
rows, cols = img.shape

sobel_horizontal = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3)
sobel_vertical = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3)
sobel=np.hypot(sobel_horizontal,sobel_vertical)
pil_img=Image.fromarray(sobel).convert('RGB')
pil_img.save('result_sobel.png')
Binary file added OpenCV/test_kernel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ba90ed

Please sign in to comment.