{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nprint(os.listdir(\"/kaggle/input\"))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:40:55.911260Z","iopub.execute_input":"2026-07-27T17:40:55.911735Z","iopub.status.idle":"2026-07-27T17:40:55.922257Z","shell.execute_reply.started":"2026-07-27T17:40:55.911701Z","shell.execute_reply":"2026-07-27T17:40:55.921039Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(os.listdir(\"/kaggle/input/competitions\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:42:08.786501Z","iopub.execute_input":"2026-07-27T17:42:08.786950Z","iopub.status.idle":"2026-07-27T17:42:08.792770Z","shell.execute_reply.started":"2026-07-27T17:42:08.786911Z","shell.execute_reply":"2026-07-27T17:42:08.791922Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"comp_path = \"/kaggle/input/competitions/beyond-visible-spectrum-ai-for-agriculture-2024\"\nprint(os.listdir(comp_path))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:43:51.944297Z","iopub.execute_input":"2026-07-27T17:43:51.945498Z","iopub.status.idle":"2026-07-27T17:43:51.953365Z","shell.execute_reply.started":"2026-07-27T17:43:51.945456Z","shell.execute_reply":"2026-07-27T17:43:51.952169Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"archive_path = os.path.join(comp_path, \"archive\")\nprint(os.listdir(archive_path))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:46:07.825594Z","iopub.execute_input":"2026-07-27T17:46:07.825965Z","iopub.status.idle":"2026-07-27T17:46:07.837097Z","shell.execute_reply.started":"2026-07-27T17:46:07.825933Z","shell.execute_reply":"2026-07-27T17:46:07.835678Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_path = os.path.join(archive_path, \"train\")\nprint(os.listdir(train_path))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:47:24.290945Z","iopub.execute_input":"2026-07-27T17:47:24.291379Z","iopub.status.idle":"2026-07-27T17:47:24.327358Z","shell.execute_reply.started":"2026-07-27T17:47:24.291346Z","shell.execute_reply":"2026-07-27T17:47:24.326378Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"health_path = os.path.join(train_path, \"Health\")\nprint(os.listdir(health_path)[:20])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:50:12.451502Z","iopub.execute_input":"2026-07-27T17:50:12.452265Z","iopub.status.idle":"2026-07-27T17:50:12.475490Z","shell.execute_reply.started":"2026-07-27T17:50:12.452228Z","shell.execute_reply":"2026-07-27T17:50:12.474721Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import glob\nhealth_files = glob.glob(os.path.join(health_path, \"*.tif\"))\n\nprint(\"Number of Health images:\", len(health_files))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:51:49.766532Z","iopub.execute_input":"2026-07-27T17:51:49.767407Z","iopub.status.idle":"2026-07-27T17:51:49.775545Z","shell.execute_reply.started":"2026-07-27T17:51:49.767371Z","shell.execute_reply":"2026-07-27T17:51:49.774546Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(health_files[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:52:41.881197Z","iopub.execute_input":"2026-07-27T17:52:41.882354Z","iopub.status.idle":"2026-07-27T17:52:41.887284Z","shell.execute_reply.started":"2026-07-27T17:52:41.882311Z","shell.execute_reply":"2026-07-27T17:52:41.886274Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tifffile\n\nimage_path = health_files[0]\n\nimage = tifffile.imread(image_path)\n\nprint(\"Image loaded successfully!\")\nprint(\"Image shape:\", image.shape)\nprint(\"Data type:\", image.dtype)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:54:31.251715Z","iopub.execute_input":"2026-07-27T17:54:31.252306Z","iopub.status.idle":"2026-07-27T17:54:31.644529Z","shell.execute_reply.started":"2026-07-27T17:54:31.252270Z","shell.execute_reply":"2026-07-27T17:54:31.643052Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Minimum value:\", image.min())\nprint(\"Maximum value:\", image.max())\nprint(\"Mean value:\", image.mean())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T17:57:54.832361Z","iopub.execute_input":"2026-07-27T17:57:54.833024Z","iopub.status.idle":"2026-07-27T17:57:54.840455Z","shell.execute_reply.started":"2026-07-27T17:57:54.832983Z","shell.execute_reply":"2026-07-27T17:57:54.839633Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from collections import Counter\n\nimage_shapes = Counter()\n\nfor file_path in health_files:\n    img = tifffile.imread(file_path)\n    image_shapes[img.shape] += 1\n\nprint(image_shapes)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:00:30.777158Z","iopub.execute_input":"2026-07-27T18:00:30.777525Z","iopub.status.idle":"2026-07-27T18:00:34.526759Z","shell.execute_reply.started":"2026-07-27T18:00:30.777494Z","shell.execute_reply":"2026-07-27T18:00:34.525457Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for file_path in health_files:\n    img = tifffile.imread(file_path)\n\n    if img.shape == (64, 64, 126):\n        print(os.path.basename(file_path))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:03:24.882143Z","iopub.execute_input":"2026-07-27T18:03:24.883052Z","iopub.status.idle":"2026-07-27T18:03:25.466434Z","shell.execute_reply.started":"2026-07-27T18:03:24.883007Z","shell.execute_reply":"2026-07-27T18:03:25.465529Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_125_path = None\nimage_126_path = None\n\nfor file_path in health_files:\n    img = tifffile.imread(file_path)\n\n    if img.shape == (64, 64, 125) and image_125_path is None:\n        image_125_path = file_path\n\n    elif img.shape == (64, 64, 126) and image_126_path is None:\n        image_126_path = file_path\n\n    if image_125_path is not None and image_126_path is not None:\n        break\n\nprint(\"125-band image:\", os.path.basename(image_125_path))\nprint(\"126-band image:\", os.path.basename(image_126_path))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:05:12.071650Z","iopub.execute_input":"2026-07-27T18:05:12.071989Z","iopub.status.idle":"2026-07-27T18:05:12.087680Z","shell.execute_reply.started":"2026-07-27T18:05:12.071958Z","shell.execute_reply":"2026-07-27T18:05:12.086618Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_125 = tifffile.imread(image_125_path)\nimage_126 = tifffile.imread(image_126_path)\n\nprint(\"125-band image shape:\", image_125.shape)\nprint(\"126-band image shape:\", image_126.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:09:28.775432Z","iopub.execute_input":"2026-07-27T18:09:28.775875Z","iopub.status.idle":"2026-07-27T18:09:28.794785Z","shell.execute_reply.started":"2026-07-27T18:09:28.775841Z","shell.execute_reply":"2026-07-27T18:09:28.793622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"125-band image:\")\nprint(\"First band:\", image_125[:, :, 0].mean())\nprint(\"Last band:\", image_125[:, :, -1].mean())\n\nprint(\"\\n126-band image:\")\nprint(\"First band:\", image_126[:, :, 0].mean())\nprint(\"Last band:\", image_126[:, :, -1].mean())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:09:55.110690Z","iopub.execute_input":"2026-07-27T18:09:55.112265Z","iopub.status.idle":"2026-07-27T18:09:55.120662Z","shell.execute_reply.started":"2026-07-27T18:09:55.112221Z","shell.execute_reply":"2026-07-27T18:09:55.119183Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\npixel_125 = image_125[32, 32, :]\npixel_126 = image_126[32, 32, :]\n\nplt.figure(figsize=(10, 5))\n\nplt.plot(pixel_125, label=\"125-band image\")\nplt.plot(pixel_126, label=\"126-band image\")\n\nplt.xlabel(\"Spectral Band\")\nplt.ylabel(\"Pixel Value\")\nplt.title(\"Spectral Profile Comparison\")\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:12:24.970469Z","iopub.execute_input":"2026-07-27T18:12:24.971494Z","iopub.status.idle":"2026-07-27T18:12:25.232732Z","shell.execute_reply.started":"2026-07-27T18:12:24.971397Z","shell.execute_reply":"2026-07-27T18:12:25.231684Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"last_band_means = []\n\nfor file_path in health_files:\n    img = tifffile.imread(file_path)\n\n    if img.shape == (64, 64, 126):\n        last_band_mean = img[:, :, -1].mean()\n        last_band_means.append(last_band_mean)\n\nprint(\"Number of 126-band images:\", len(last_band_means))\nprint(\"Last-band means:\")\nprint(last_band_means)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:16:24.597430Z","iopub.execute_input":"2026-07-27T18:16:24.598042Z","iopub.status.idle":"2026-07-27T18:16:25.743068Z","shell.execute_reply.started":"2026-07-27T18:16:24.598005Z","shell.execute_reply":"2026-07-27T18:16:25.742180Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nfor file_path in health_files:\n    \n    img = tifffile.imread(file_path)\n\n    if img.shape == (64, 64, 126):\n        \n        last_band = img[:, :, -1]\n\n        print(\n            os.path.basename(file_path),\n            \"min =\", last_band.min(),\n            \"max =\", last_band.max(),\n            \"unique values =\", len(np.unique(last_band))\n        )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:25:06.781714Z","iopub.execute_input":"2026-07-27T18:25:06.782248Z","iopub.status.idle":"2026-07-27T18:25:07.717714Z","shell.execute_reply.started":"2026-07-27T18:25:06.782215Z","shell.execute_reply":"2026-07-27T18:25:07.716822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_image = tifffile.imread(image_126_path)\n\nprint(test_image.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:29:58.103254Z","iopub.execute_input":"2026-07-27T18:29:58.103736Z","iopub.status.idle":"2026-07-27T18:29:58.121504Z","shell.execute_reply.started":"2026-07-27T18:29:58.103702Z","shell.execute_reply":"2026-07-27T18:29:58.120326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for band in range(test_image.shape[2]):\n    \n    band_data = test_image[:, :, band]\n    \n    print(\n        \"Band:\", band + 1,\n        \"| Min:\", band_data.min(),\n        \"| Max:\", band_data.max(),\n        \"| Mean:\", band_data.mean(),\n        \"| Unique values:\", len(np.unique(band_data))\n    )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:30:45.106154Z","iopub.execute_input":"2026-07-27T18:30:45.106701Z","iopub.status.idle":"2026-07-27T18:30:45.162090Z","shell.execute_reply.started":"2026-07-27T18:30:45.106667Z","shell.execute_reply":"2026-07-27T18:30:45.161179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for file_path in health_files:\n\n    img = tifffile.imread(file_path)\n\n    if img.shape == (64, 64, 126):\n\n        print(\"\\n\", os.path.basename(file_path))\n\n        for band in range(126):\n\n            unique_count = len(np.unique(img[:, :, band]))\n\n            if unique_count <= 2:\n                print(\n                    \"Suspicious Band:\",\n                    band + 1,\n                    \"| Unique values:\",\n                    unique_count\n                )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-27T18:36:51.723103Z","iopub.execute_input":"2026-07-27T18:36:51.724198Z","iopub.status.idle":"2026-07-27T18:36:53.751363Z","shell.execute_reply.started":"2026-07-27T18:36:51.724160Z","shell.execute_reply":"2026-07-27T18:36:53.750377Z"}},"outputs":[],"execution_count":null}]}