{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from glob import glob \nimport os,cv2\nimport tqdm ,shutil\ntarget_path=\"./\"\nif not os.path.exists(target_path):\n    os.mkdir(target_path)\n    \nshutil.copy(\"/kaggle/input/vesuvius-challenge-ink-detection/sample_submission.csv\",\"./sample_submission.csv\")\nprint(\"load to\"+\"./sample_submission.csv\")\n    \nfor data_source in [\"train\",\"test\"]:\n    for scr in glob(f\"/kaggle/input/vesuvius-challenge-ink-detection/{data_source}/*/*\",recursive=True):\n        path=\"/\".join(scr.split(\"/\")[-3:])\n        path=target_path+path\n        if not os.path.exists(\"/\".join(path.split(\"/\")[:-2])):\n            os.mkdir(\"/\".join(path.split(\"/\")[:-2]))\n        if not os.path.exists(\"/\".join(path.split(\"/\")[:-1])):\n            os.mkdir(\"/\".join(path.split(\"/\")[:-1]))\n        if os.path.isdir(scr):\n            continue\n        print(\"load to\"+path)\n        shutil.copy(scr,path)\n\n\n    for path in tqdm.tqdm(glob(f\"/kaggle/input/vesuvius-challenge-ink-detection/{data_source}/*/surface_volume/*.tif\",recursive=True)):\n        image = cv2.imread(path, 0)\n        path=\"/\".join(path.split(\"/\")[-4:])[:-4]\n        path=target_path+path\n        #print(image.shape)\n\n        if not os.path.exists(\"/\".join(path.split(\"/\")[:-3])):\n            os.mkdir(\"/\".join(path.split(\"/\")[:-3]))\n        if not os.path.exists(\"/\".join(path.split(\"/\")[:-2])):\n            os.mkdir(\"/\".join(path.split(\"/\")[:-2]))\n        if not os.path.exists(\"/\".join(path.split(\"/\")[:-1])):\n            os.mkdir(\"/\".join(path.split(\"/\")[:-1]))\n        #print(\"load to\"+path)\n        cv2.imwrite(path+\".png\", image, [cv2.IMWRITE_PNG_COMPRESSION, 9])\n        #cv2.imwrite(path+\".jpg\", image, [cv2.IMWRITE_JPEG_QUALITY, 0])\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-08T09:06:46.071481Z","iopub.execute_input":"2023-05-08T09:06:46.072171Z"},"trusted":true},"execution_count":null,"outputs":[]}]}