{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":117682,"databundleVersionId":14443416,"sourceType":"competition"}],"dockerImageVersionId":30408,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Surface Detection Masked Image","metadata":{}},{"cell_type":"code","source":"import os\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib import animation, rc\nrc('animation', html='jshtml')\nfrom tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2025-11-15T03:26:37.184339Z","iopub.execute_input":"2025-11-15T03:26:37.184692Z","iopub.status.idle":"2025-11-15T03:26:37.189662Z","shell.execute_reply.started":"2025-11-15T03:26:37.184660Z","shell.execute_reply":"2025-11-15T03:26:37.188681Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mpaths0=[]\ntpaths0=[]\nmfold='/kaggle/input/vesuvius-challenge-surface-detection/train_labels'\nfor dirname, _, filenames in os.walk('/kaggle/input/vesuvius-challenge-surface-detection/train_images'):\n    for filename in filenames:\n        if filename[-4:]=='.tif':\n            tpaths0+=[(os.path.join(dirname, filename))]\n            mpaths0+=[(os.path.join(mfold, filename))]\ntpaths=sorted(tpaths0)[0:5]\nmpaths=sorted(mpaths0)[0:5]","metadata":{"execution":{"iopub.status.busy":"2025-11-15T03:26:37.191948Z","iopub.execute_input":"2025-11-15T03:26:37.192405Z","iopub.status.idle":"2025-11-15T03:26:37.788856Z","shell.execute_reply.started":"2025-11-15T03:26:37.192369Z","shell.execute_reply":"2025-11-15T03:26:37.787782Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"timg=[]\nfor path in tpaths:\n    img=cv2.imread(path)\n    timg+=[img]\nmimg=[]\nfor path in mpaths:\n    img=cv2.imread(path)\n    mimg+=[img]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-15T03:26:37.790367Z","iopub.execute_input":"2025-11-15T03:26:37.790651Z","iopub.status.idle":"2025-11-15T03:26:37.818582Z","shell.execute_reply.started":"2025-11-15T03:26:37.790625Z","shell.execute_reply":"2025-11-15T03:26:37.817903Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"np.unique(mimg[0])","metadata":{"execution":{"iopub.status.busy":"2025-11-15T03:26:37.819637Z","iopub.execute_input":"2025-11-15T03:26:37.819967Z","iopub.status.idle":"2025-11-15T03:26:37.830909Z","shell.execute_reply.started":"2025-11-15T03:26:37.819932Z","shell.execute_reply":"2025-11-15T03:26:37.829939Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"img = timg[0]\nmask0 = (mimg[0] == 0)\nmask1 = (mimg[0] == 1)\nmask2 = (mimg[0] == 2)\nmasked0 = np.where(mask0, img, 200)\nmasked1 = np.where(mask1, img, 200)\nmasked2 = np.where(mask2, img, 200)\n\nfig, axs = plt.subplots(1, 4, figsize=(10,4))\n\naxs[0].imshow(img)\naxs[1].imshow(masked0)\naxs[2].imshow(masked1)\naxs[3].imshow(masked2)\n\nfor ax in axs:\n    ax.axis('off')\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-15T03:27:00.617276Z","iopub.execute_input":"2025-11-15T03:27:00.618006Z","iopub.status.idle":"2025-11-15T03:27:00.827294Z","shell.execute_reply.started":"2025-11-15T03:27:00.617973Z","shell.execute_reply":"2025-11-15T03:27:00.826038Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}