{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"tpuV5e8","dataSources":[{"sourceType":"competition","sourceId":130932,"databundleVersionId":15769099}],"dockerImageVersionId":31288,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nfrom PIL import Image  # this will now use Pillow-SIMD\nfrom tqdm import tqdm\nfrom multiprocessing import Pool, cpu_count\n\n# Input and output directories\ninput_dir = \"/kaggle/input/automatic-lens-correction/lens-correction-train-cleaned\"\noutput_dir = \"/kaggle/working/train_resized\"\n\nos.makedirs(output_dir, exist_ok=True)\n\n# Collect image files\nimg_files = [f for f in os.listdir(input_dir) if f.lower().endswith((\".png\", \".jpg\", \".jpeg\"))]\n\ndef resize_and_save(fname):\n    try:\n        in_path = os.path.join(input_dir, fname)\n        out_path = os.path.join(output_dir, fname)\n\n        # Open with Pillow-SIMD and resize\n        img = Image.open(in_path).convert(\"RGB\")\n        img = img.resize((896, 896), Image.BILINEAR)\n\n        # Save as JPEG (quality=95 = good tradeoff)\n        img.save(out_path, \"JPEG\", quality=100, optimize=True)\n    except Exception as e:\n        print(f\"❌ Error processing {fname}: {e}\")\n\n# Use all available CPU cores for speed\nwith Pool(processes=cpu_count()) as pool:\n    list(tqdm(pool.imap_unordered(resize_and_save, img_files), total=len(img_files)))\n\nprint(\"✅ All images resized to 896×896 and saved in:\", output_dir)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-02-22T01:31:04.502134Z","iopub.execute_input":"2026-02-22T01:31:04.502369Z","iopub.status.idle":"2026-02-22T01:32:37.258739Z","shell.execute_reply.started":"2026-02-22T01:31:04.502350Z","shell.execute_reply":"2026-02-22T01:32:37.257548Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}