-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdd61d3
commit 0ba90ed
Showing
21 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.