{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os \nimport cv2\nimport glob\nimport imageio\nimport numpy as np\nfrom tqdm import tqdm\nfrom pathlib import Path\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"TOMAKE = 1024 #512, 256\nPATH = '../input/vinbigdata-{}-image-dataset/vinbigdata/'.format(TOMAKE)\nTRAIN_FILES, TEST_FILES = PATH + 'train', PATH + 'test'\n\n\ntrain_files = glob.glob(TRAIN_FILES + '/*.png')\ntest_files = glob.glob(TEST_FILES + '/*.png')\ncsv_files = glob.glob(PATH + '/*.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def clahe(files):\n    CLIP_LIMIT=2.0\n    GRID_SIZE = (10, 10)\n    clahe = cv2.createCLAHE(clipLimit=CLIP_LIMIT, tileGridSize=GRID_SIZE)\n    tosave = [os.path.join(\"vinbigdata\", *file.split('/')[-2:]) for file in files]\n    for reads, saves in tqdm(zip(files, tosave)):\n        temp = cv2.imread(reads, 0)\n        temp2 = clahe.apply(temp)\n        temp2 = cv2.cvtColor(temp2, cv2.COLOR_GRAY2BGR)\n        imageio.imwrite(saves, temp2)\n    \n\ndef copy_csv(files):\n    from shutil import copyfile\n    for src in files:\n        copyfile(src, 'vinbigdata/'+ src.split('/')[-1])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"if not os.path.exists('vinbigdata'):\n    os.mkdir('vinbigdata')\n    os.mkdir('vinbigdata/train')\n    os.mkdir('vinbigdata/test')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"clahe(train_files)\nclahe(test_files)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"copy_csv(csv_files)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!zip -r -qq \"vinbigdata.zip\" vinbigdata/\n!rm -rf 'vinbigdata'","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}