forked from yumjuice/opensource
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage_final.py
More file actions
61 lines (58 loc) · 1.85 KB
/
Image_final.py
File metadata and controls
61 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from PIL import Image
from matplotlib import image
from matplotlib import pyplot
class Image:
def __init__(self, address):
self.address=address
def openImage(self):
data=Image.open(self.address)
print(data.size)
return data
def imageArray(self):
data=image.imread(self.address)
print(data.dtype)
print(data.shape)
return pyplot.imshow(data)
def resizeImage(self, x, y):
data=Image.open(self.address)
print(data.size)
data_resized=data.resize((x, y))
print(data_resized.size)
return data_resized
def rotateImage(self, rotate):
data=Image.open(self.address)
pyplot.imshow(data.rotate(rotate))
pyplot.show()
def flipImage(self, direc):
data=Image.open(self.address)
if direc=="hoz":
hoz_flip=data.transpose(Image.FLIP_LEFT_RIGHT)
pyplot.imshow(hoz_flip)
elif direc=="ver":
ver_flip=data.transpose(Image.FLIP_TOP_BOTTOM)
pyplot.imshow(ver_flip)
else:
print("Please insert either 'hoz' or 'ver'")
def cropImage(self, x1, x2, y1, y2):
data=Image.open(self.address)
cropped=data.crop((x1, x2, y1, y2))
return cropped
class Image_save:
def __init__(self, file):
self.file=file
def save_jpg(self, title):
save_title=title+".jpg"
self.file.save(save_title)
print("Successfully saved!")
def save_png(self, title):
save_title=title+".png"
self.file.save(save_title)
print("Successfully saved!")
def save_tif(self, title):
save_title=title+".tif"
self.file.save(save_title)
print("Successfully saved!")
def save_bmp(self, title):
save_title=title+".bmp"
self.file.save(save_title)
print("Successfully saved!")