summaryrefslogtreecommitdiff
path: root/dataset_utils.py
blob: fda75d2e0e06fee6a1641258a2221388ae39a7e2 (plain)
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 numpy
from PIL import Image
from pathlib import Path

"""Class to interface the training and testing data."""
class DatasetUtils:
    def __init__(self) -> None:
        self.data_path = Path('./data')

    """Convert the dataset to a 2 dimension array."""
    def data_to_arrays(self):
        for dir in self.data_path.iterdir():
            if not dir.is_dir(): continue

            for file in dir.glob('*.png'):
                image = Image.open(str(file)).convert(mode='L')
                # Return the image's pixel values as an array alongside
                # the character that it represents.
                yield (dir.name, numpy.asarray(image).ravel())

    """Search for a file in the dataset."""
    def search(self, filename: str):
        pass

    def get_random_sample(self):
        pass