forked from lucaskjaero/chinese-character-recognizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_exploration.py
39 lines (30 loc) · 1.12 KB
/
data_exploration.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
import glob
from IPython.display import display, Image
from io import BytesIO
from PIL import Image as Pil
__author__ = 'Lucas Kjaero'
EXPLORATION_DIR = "raw/competition-gnt/"
def identity_function(image):
"""
Default image transformation function. Does nothing.
:param image: The image to transform.
:return: The original image.
"""
return image
def display_label(label, transform=identity_function, directory=EXPLORATION_DIR):
"""
Displays all the images with a given label.
:param label: The label to look at.
:param transform: A function to process the images.
:param directory: The path to the dataset to display. Default is "competition-gnt"
:return: Nothing
"""
base = directory + "%s/" % label
for path in glob.glob(base + "*.jpg"):
pil_image = transform(Pil.open(path))
# Fix to make display work. Somehow greyscale doesn't work.
pil_image = pil_image.convert('RGB')
image_bytes = BytesIO()
pil_image.save(image_bytes, format="jpeg")
ip_image = Image(data=image_bytes.getvalue(), format="jpeg")
display(ip_image)