Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 4ec5ada

Browse files
Add files via upload
1 parent d759d1c commit 4ec5ada

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

split_quadrant.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import cv2
3+
import numpy as np
4+
import glob
5+
6+
# Loop through every file ending with .png in the file.
7+
for filename in glob.glob('*.png'):
8+
# Print the image name.
9+
print(filename)
10+
11+
# Load the image.
12+
img = cv2.imread(filename)
13+
14+
# Split the image into four equal parts.
15+
h, w, c = img.shape
16+
quad1 = img[0:h//2, 0:w//2]
17+
quad2 = img[0:h//2, w//2:w]
18+
quad3 = img[h//2:h, 0:w//2]
19+
quad4 = img[h//2:h, w//2:w]
20+
21+
# Create filenames for each quadrant.
22+
name_quad1 = filename[:-4] + '_quad1.png'
23+
name_quad2 = filename[:-4] + '_quad2.png'
24+
name_quad3 = filename[:-4] + '_quad3.png'
25+
name_quad4 = filename[:-4] + '_quad4.png'
26+
27+
# Create a new folder with the same name as the original image.
28+
os.mkdir(filename[:-4])
29+
30+
# Save the four images in the newly created folder.
31+
cv2.imwrite(os.path.join(filename[:-4], name_quad1), quad1)
32+
cv2.imwrite(os.path.join(filename[:-4], name_quad2), quad2)
33+
cv2.imwrite(os.path.join(filename[:-4], name_quad3), quad3)
34+
cv2.imwrite(os.path.join(filename[:-4], name_quad4), quad4)
35+
36+
37+
# Delete the original image.
38+
os.remove(filename)
39+

0 commit comments

Comments
 (0)