-
Notifications
You must be signed in to change notification settings - Fork 0
/
insideBox.py
54 lines (43 loc) · 1.33 KB
/
insideBox.py
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
from PIL import Image
import matplotlib.pyplot as plt
# Specify the path to the image file
image_path = r'D:/_phd/code/textures/textureSSD/findBox/z1Sample.png'
# Load the image
image = Image.open(image_path)
# Show the image using matplotlib
plt.figure()
plt.imshow(image)
plt.title('Original Image')
plt.axis('off')
plt.show()
# Specify the coordinates of the inside box
left = 100
top = 100
right = 300
bottom = 300
# Crop the image to get the inside box
inside_box = image.crop((left, top, right, bottom))
# Show the inside box image using matplotlib
plt.figure()
plt.imshow(inside_box)
plt.title('Inside Box Image')
plt.axis('off')
plt.show()
# Find the biggest crop coordinates
max_crop_size = max(image.size[0] - left, right - left, image.size[1] - top, bottom - top)
# Calculate the center coordinates of the biggest crop
center_x = (left + right) // 2
center_y = (top + bottom) // 2
# Calculate the new crop coordinates
new_left = center_x - max_crop_size // 2
new_top = center_y - max_crop_size // 2
new_right = center_x + max_crop_size // 2
new_bottom = center_y + max_crop_size // 2
# Crop the image to get the biggest crop
biggest_crop = image.crop((new_left, new_top, new_right, new_bottom))
# Show the biggest crop image using matplotlib
plt.figure()
plt.imshow(biggest_crop)
plt.title('Biggest Crop Image')
plt.axis('off')
plt.show()