Datasets:

Modalities:
Image
Formats:
parquet
Languages:
English
DOI:
Libraries:
Datasets
Dask
License:
File size: 955 Bytes
ae6e9e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#! /usr/bin/env python3

# Image dataset pre processor with name normalization
# by Jiri Podivin 2023
# v1.0

import os
import glob
import hashlib
import argparse
import re
import shutil

def main(source_path, dest_path):
    
    img_paths = [
        e for e in glob.glob(os.path.join(source_path, '**'))
        if re.match(".*\.jpe?g", e, flags=re.IGNORECASE)]

    for image in img_paths:
        print(image)
        path_hash = hashlib.sha1(image.encode()).hexdigest()
        name_hash = hashlib.sha1(os.path.basename(image.encode())).hexdigest()
        new_name = f"{path_hash[:10]}_{name_hash[:10]}.jpg"
        shutil.copy(image, os.path.join(dest_path, new_name))
        print(new_name)

if __name__ == '__main__':
    parser = argparse.ArgumentParser("imageprocessor")

    parser.add_argument("source_path", type=str)
    parser.add_argument("dest_path", type=str)
    args = parser.parse_args()
    main(args.source_path, args.dest_path)