-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize_images.py
41 lines (31 loc) · 1.94 KB
/
resize_images.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import cv2
from os import listdir
from os.path import isfile, join
SHAPE = 96
def getImagesFromDir(directory):
onlyfiles = [f for f in listdir(directory) if isfile(join(directory, f))]
return onlyfiles, directory
def resizeImages(files, directory):
for f in files:
print(f)
image = cv2.imread(join(directory, f))
img = cv2.resize(image, (SHAPE, SHAPE), interpolation=cv2.INTER_AREA)
cv2.imwrite(join(directory, f), img)
# files = getImagesFromDir('/home/user/Efficient-CapsNet/covid-chestxray-dataset/images_ok/bacteria')
# print(files)
# bacteria_files = getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/images_ok/bacteria')
# print(bacteria_files)
# resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/images_ok/bacteria'))
# resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/images_ok/healthy'))
# resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/images_ok/viral/covid-19'))
# resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/images_ok/viral/other'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/train/bacteria'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/train/healthy'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/train/viral_covid-19'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/train/viral_other'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/test/bacteria'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/test/healthy'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/test/viral_covid-19'))
resizeImages(*getImagesFromDir('/root/Efficient-CapsNet/covid-chestxray-dataset/test/viral_other'))