Skip to content

Commit 1cfdebd

Browse files
committed
Completed
1 parent 17df806 commit 1cfdebd

18 files changed

+740
-59
lines changed

InterfaceFunctions.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ def __init__(self, master=None):
1818
self.rectangle_id = 0
1919
self.ratio = 0
2020
self.rotate_angle = 0
21+
self.forward_cache = list()
2122

2223
self.canvas = Canvas(self, bg="black", width=1280, height=720)
2324
self.canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
2425

25-
def show_image(self, img=None):
26+
def show_image(self, image=None):
2627
self.clear_canvas()
2728

28-
if img is None:
29+
if image is None:
2930
image = self.master.processed_image.copy()
3031
else:
31-
image = img
32+
image = image
3233

3334
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
3435
height, width, channels = image.shape
@@ -54,24 +55,39 @@ def show_image(self, img=None):
5455
self.canvas.create_image(new_width / 2, new_height / 2, anchor=CENTER, image=self.shown_image)
5556

5657
def contrast(self):
58+
self.master.image_cache.append(self.master.processed_image.copy())
5759
contrast = (ImageEnhance.Contrast(Image.fromarray(self.master.processed_image))).enhance(1.1)
5860
self.master.processed_image = np.array(contrast)
61+
self.master.image_cache.append(self.master.processed_image.copy())
5962
self.show_image()
6063

6164
def flipping(self):
65+
self.master.image_cache.append(self.master.processed_image.copy())
6266
flipping_image = Image.fromarray(self.master.processed_image).copy()
6367
flipping_image = flipping_image.transpose(Image.FLIP_LEFT_RIGHT)
6468
self.master.processed_image = np.array(flipping_image).copy()
69+
self.master.image_cache.append(self.master.processed_image.copy())
6570
self.show_image()
6671

67-
def resizing(self, x=100, y=100):
72+
def resizing(self, x, y):
73+
if x or y == '':
74+
x, y = 500, 500
75+
else:
76+
x, y = int(x), int(y)
77+
self.master.image_cache.append(self.master.processed_image.copy())
6878
self.master.processed_image = np.array(Image.fromarray(self.master.processed_image).resize((x, y)))
79+
self.master.image_cache.append(self.master.processed_image.copy())
6980
self.show_image()
7081

7182
def rotate(self, rotateAngle):
83+
if rotateAngle == '':
84+
rotateAngle = 60
85+
else:
86+
float(rotateAngle)
7287
self.rotate_angle += rotateAngle
7388
self.master.rotating_image = np.array(Image.fromarray(self.master.processed_image).rotate(self.rotate_angle))
74-
self.show_image(img=self.master.rotating_image)
89+
self.master.image_cache.append(self.master.rotating_image.copy())
90+
self.show_image(image=self.master.rotating_image)
7591

7692
def activate_paste(self):
7793
self.canvas.bind("<ButtonPress>", self.start_paste)
@@ -114,11 +130,12 @@ def deactivate_crop(self):
114130
self.master.is_crop_state = False
115131

116132
def start_paste(self, event):
133+
self.master.image_cache.append(self.master.processed_image.copy())
117134
self.x = event.x
118135
self.y = event.y
119136

120137
def start_draw(self, event):
121-
self.master.drawing_cache.append(self.master.processed_image.copy())
138+
self.master.image_cache.append(self.master.processed_image.copy())
122139
self.x = event.x
123140
self.y = event.y
124141

@@ -152,6 +169,7 @@ def draw(self, event):
152169
self.y = event.y
153170

154171
def start_crop(self, event):
172+
self.master.image_cache.append(self.master.processed_image.copy())
155173
self.crop_start_x = event.x
156174
self.crop_start_y = event.y
157175

@@ -191,16 +209,21 @@ def end_crop(self, event):
191209
y = slice(start_y, end_y, 1)
192210

193211
self.master.processed_image = self.master.processed_image[y, x]
212+
self.master.image_cache.append(self.master.processed_image.copy())
194213

195214
self.show_image()
196215

197216
def clear_canvas(self):
198217
self.canvas.delete("all")
199218

200-
def clear_draw(self):
201-
# if u use some filter or adjust after drawing, u lost your filter and adjust changes when released clear draw
202-
# But if u want to not to lost your changes u should add self.master.drawing_cache[0]
203-
# to other parts with processed image. U should change drawing_cache[0] when you change processed_image
204-
if self.master.drawing_cache:
205-
self.master.processed_image = self.master.drawing_cache.pop()
219+
def undo_image(self):
220+
if self.master.image_cache:
221+
self.master.processed_image = self.master.image_cache.pop()
222+
self.forward_cache.append(self.master.processed_image)
223+
self.show_image()
224+
225+
def forward_image(self):
226+
if self.forward_cache:
227+
self.master.processed_image = self.forward_cache.pop()
228+
self.master.image_cache.append(self.master.processed_image)
206229
self.show_image()

ReadMe.docx

33.3 MB
Binary file not shown.
8.57 MB
Binary file not shown.

Sample_Images/CreationOfAdam1.jpg

116 KB
Loading
7.62 KB
Binary file not shown.
9.06 KB
Binary file not shown.
3.9 KB
Binary file not shown.
5.04 KB
Binary file not shown.
6.81 KB
Binary file not shown.
9.41 KB
Binary file not shown.

0 commit comments

Comments
 (0)