{"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"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":112899,"databundleVersionId":13449579,"sourceType":"competition"}],"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/grand-xray-slam-division-a/train1\"\noutput_dir = \"/kaggle/working/train1_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((600, 600), Image.BILINEAR)\n\n        # Save as JPEG (quality=95 = good tradeoff)\n        img.save(out_path, \"JPEG\", quality=95, 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 600×600 and saved in:\", output_dir)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Input and output directories\ninput_dir = \"/kaggle/input/grand-xray-slam-division-a/test1\"\noutput_dir = \"/kaggle/working/test1_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((600, 600), Image.BILINEAR)\n\n        # Save as JPEG (quality=95 = good tradeoff)\n        img.save(out_path, \"JPEG\", quality=95, 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 600×600 and saved in:\", output_dir)","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}