-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSliced_image_classification.py
26 lines (23 loc) · 1.17 KB
/
Sliced_image_classification.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
import glob
import cv2
import numpy as np
import shutil
path = glob.glob(r'C:\Users\cleos\Desktop\BachelorProject\Trypanosome\data\train\mask\crop\*.png')
for path_to_img in path:
filename = path_to_img[-17:-4]
print(filename)
img = cv2.imread(path_to_img, 0)
#cv2.imshow('image', img)
#cv2.waitKey(0)
# Count white pixels
histogram, bin_edges = np.histogram(img, bins=2, range=(0, 256))
white_pixels = histogram[1]
# Redistribute original images according to existence of white pixels
if white_pixels != 0:
path_to_original_image = r'C:\Users\cleos\Desktop\BachelorProject\Trypanosome\data\train\original\crop\{}.png'.format(filename)
path_to_positive_folder = r'C:\Users\cleos\Desktop\BachelorProject\Trypanosome\data\train\pos'
shutil.move(path_to_original_image, path_to_positive_folder)
else:
path_to_original_image = r'C:\Users\cleos\Desktop\BachelorProject\Trypanosome\data\train\original\crop\{}.png'.format(filename)
path_to_negative_folder = r'C:\Users\cleos\Desktop\BachelorProject\Trypanosome\data\train\neg'
shutil.move(path_to_original_image, path_to_negative_folder)