File size: 1,392 Bytes
5f0437a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
"""
Created by Myung-Joon Kwon
mjkwon2021@gmail.com
July 14, 2020

modified by Fabrizio Guillaro
fabrizio.guillaro@unina.it
September 2022
"""

from project_config import project_root, dataset_paths
from dataset.AbstractDataset import AbstractDataset

import os
import numpy as np
from PIL import Image


class CASIA(AbstractDataset):
    """
    directory structure:
    CASIA2.0_revised
    β”œβ”€β”€ Au
    β”œβ”€β”€ Tp
    └── groundtruth
    """

    def __init__(self, crop_size, grid_crop, img_list: str, max_dim=None, aug=None):
        super().__init__(crop_size, grid_crop, max_dim, aug=aug)
        self._root_path    = dataset_paths['CA']
        
        with open(project_root / img_list, "r") as f:
            self.img_list = [t.strip().split(',') for t in f.readlines()]
        
        

    def get_img(self, index):
        assert 0 <= index < len(self.img_list), f"Index {index} is not available!"
        
        root = self._root_path

        mask_path = os.path.join(root, self.img_list[index][1])
        rgb_path  = os.path.join(root, self.img_list[index][0])
            
        if self.img_list[index][1] == 'None':
            mask = None
        else:
            mask = np.array(Image.open(mask_path).convert("L"))
            mask[mask > 0] = 1

        assert os.path.isfile(rgb_path)
        return self._create_tensor(mask=mask, rgb_path=rgb_path)