{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":117682,"databundleVersionId":14443416,"sourceType":"competition"}],"dockerImageVersionId":31192,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Published on November 13, 2025. By Marília Prata, mpwolke","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n#Two lines Required to Plot Plotly\nimport plotly.io as pio\npio.renderers.default = 'iframe'\n\nimport plotly.graph_objs as go\nimport plotly.offline as py\nimport plotly.express as px\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-11-13T20:40:37.610234Z","iopub.execute_input":"2025-11-13T20:40:37.610476Z","iopub.status.idle":"2025-11-13T20:40:47.434752Z","shell.execute_reply.started":"2025-11-13T20:40:37.610452Z","shell.execute_reply":"2025-11-13T20:40:47.434073Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"_kg_hide-output":true,"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTHOBTVTporsrFvGSD7809EQMUJfdpitL5axQ&s)Facebook","metadata":{}},{"cell_type":"markdown","source":"## About Competition: Villa dei Papiri\n\n\"Before we can recover what’s written between the lines, we first need to find the lines. You’ll work with CT scans from the Villa dei Papiri to train a model that follows the scroll’s surface, one of the trickiest and most essential parts of virtually unwrapping the text.\"\n\nhttps://www.kaggle.com/competitions/vesuvius-challenge-surface-detection/overview\n\n\"Your challenge in this competition is to **detect and segment layers of papyrus in 3D imagery**. This will help researchers virtually unroll the ancient scrolls from Herculaneum and ultimately recover the original texts.\"\n\n\"This competition uses a hidden test set. When your submitted notebook is scored, the actual test data will be made available to your notebook. Expect to see roughly 120 volumes in the hidden test set.\"\n\nhttps://www.kaggle.com/competitions/vesuvius-challenge-surface-detection/data\n\n\"The **Villa of the Papyri** (Italian: Villa dei Papiri) was an ancient Roman villa in Herculaneum, in what is now Ercolano, southern Italy. It is named after its unique **library of papyri scrolls**, discovered in 1750. The Villa was considered to be one of the most luxurious houses in all of Herculaneum and in the Roman world.\"\n\nhttps://en.wikipedia.org/wiki/Villa_of_the_Papyri","metadata":{}},{"cell_type":"markdown","source":"## Competition Citation:\n\n@misc{vesuvius-challenge-surface-detection,\n    author = {Sean Johnson and David Josey and Elian Rafael Dal Prà and Hendrik Schilling and Youssef Nader and Johannes Rudolph and Forrest McDonald and Paul Henderson and Giorgio Angelotti and Sohier Dane and María Cruz},\n    \n    title = {Vesuvius Challenge - Surface Detection},\n    year = {2025},\n    \n    howpublished = {\\url{https://kaggle.com/competitions/vesuvius-challenge-surface-detection}},\n    note = {Kaggle}\n}","metadata":{}},{"cell_type":"markdown","source":"## Import Libraries","metadata":{}},{"cell_type":"code","source":"import math\nimport time\nimport datetime\nimport glob\n\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sn\nimport json\nimport tifffile as tiff\nfrom matplotlib import colors\nfrom matplotlib.lines import Line2D\nfrom matplotlib_venn import venn2_unweighted","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T20:40:51.296809Z","iopub.execute_input":"2025-11-13T20:40:51.297508Z","iopub.status.idle":"2025-11-13T20:40:51.756322Z","shell.execute_reply.started":"2025-11-13T20:40:51.297484Z","shell.execute_reply":"2025-11-13T20:40:51.755549Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\ntrain_images = glob.glob('/kaggle/input/vesuvius-challenge-surface-detection/train_images/*.tif')\ntest_images = glob.glob('/kaggle/input/vesuvius-challenge-surface-detection/test_images/*.tif')\n\ntrain_images = list(map(lambda x: os.path.basename(x), train_images))\ntest_images = list(map(lambda x: os.path.basename(x), test_images))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:42:38.544611Z","iopub.execute_input":"2025-11-13T19:42:38.545415Z","iopub.status.idle":"2025-11-13T19:42:38.556108Z","shell.execute_reply.started":"2025-11-13T19:42:38.545385Z","shell.execute_reply":"2025-11-13T19:42:38.555162Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## The only tif file on test_images","metadata":{}},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\n# open and resize image\nimage = cv2.imread('/kaggle/input/vesuvius-challenge-surface-detection/test_images/1407735.tif')\nimage_resize = cv2.resize(image,(image.shape[1]//10,image.shape[0]//10), interpolation = cv2.INTER_CUBIC)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:46:20.461840Z","iopub.execute_input":"2025-11-13T19:46:20.462441Z","iopub.status.idle":"2025-11-13T19:46:21.141868Z","shell.execute_reply.started":"2025-11-13T19:46:20.462413Z","shell.execute_reply":"2025-11-13T19:46:21.140727Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\n# calculate colors\npixel_colors = image_resize.reshape((np.shape(image_resize)[0]*np.shape(image_resize)[1], 3))\nnorm = colors.Normalize(vmin=-1.,vmax=1.)\nnorm.autoscale(pixel_colors)\npixel_colors = norm(pixel_colors).tolist()\n\n# split channels\nb, g, r = cv2.split(image_resize)\n\n# scatter plot\nfig = plt.figure()\naxis = fig.add_subplot(1, 1, 1, projection='3d')\naxis.scatter(r.flatten(), g.flatten(), b.flatten(), facecolors=pixel_colors, marker='.')\naxis.set_xlabel('Red')\naxis.set_ylabel('Green')\naxis.set_zlabel('Blue')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:46:28.264793Z","iopub.execute_input":"2025-11-13T19:46:28.265461Z","iopub.status.idle":"2025-11-13T19:46:28.419252Z","shell.execute_reply.started":"2025-11-13T19:46:28.265432Z","shell.execute_reply":"2025-11-13T19:46:28.418425Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\n# convert to hsv\nhsv_image = cv2.cvtColor(image_resize, cv2.COLOR_BGR2HSV)\nh, s, v = cv2.split(hsv_image)\n\n# scatter plot\nfig = plt.figure()\naxis = fig.add_subplot(1, 1, 1, projection='3d')\naxis.scatter(s.flatten(), h.flatten(), v.flatten(), facecolors=pixel_colors, marker='.')\naxis.set_xlabel('Saturation')\naxis.set_ylabel('Hue')\naxis.set_zlabel('Value')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:48:19.268677Z","iopub.execute_input":"2025-11-13T19:48:19.269004Z","iopub.status.idle":"2025-11-13T19:48:19.414340Z","shell.execute_reply.started":"2025-11-13T19:48:19.268980Z","shell.execute_reply":"2025-11-13T19:48:19.413466Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Unfortunately, it didn't help much","metadata":{}},{"cell_type":"code","source":"DATA_PATH = \"../input/vesuvius-challenge-surface-detection/\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:49:31.641448Z","iopub.execute_input":"2025-11-13T19:49:31.641816Z","iopub.status.idle":"2025-11-13T19:49:31.646823Z","shell.execute_reply.started":"2025-11-13T19:49:31.641792Z","shell.execute_reply":"2025-11-13T19:49:31.645994Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_paths = sorted(glob.glob(os.path.join(DATA_PATH, 'train_images/*.tif')))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:50:06.024349Z","iopub.execute_input":"2025-11-13T19:50:06.025027Z","iopub.status.idle":"2025-11-13T19:50:06.032081Z","shell.execute_reply.started":"2025-11-13T19:50:06.025001Z","shell.execute_reply":"2025-11-13T19:50:06.031363Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## len (number of images)","metadata":{}},{"cell_type":"code","source":"print(f\"Number of images: {len(image_paths)}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:50:21.141958Z","iopub.execute_input":"2025-11-13T19:50:21.142277Z","iopub.status.idle":"2025-11-13T19:50:21.146644Z","shell.execute_reply.started":"2025-11-13T19:50:21.142253Z","shell.execute_reply":"2025-11-13T19:50:21.145717Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Display some images","metadata":{}},{"cell_type":"code","source":"#By Ruhul Amin https://www.kaggle.com/code/ruhul20/cctv-weapon-detection-yolo11s/notebook\n\nfrom pathlib import Path\nimport random\n\ntrain_images_dir = Path(\"/kaggle/input/vesuvius-challenge-surface-detection/train_images/\")\n\nimage_files = list(train_images_dir.glob(\"*.tif\"))\n\nsample_files = random.sample(image_files, min(9, len(image_files)))\n\nfig, axes = plt.subplots(3, 3, figsize=(20, 12))\naxes = axes.flatten()\n\nfor ax, img_path in zip(axes, sample_files):\n    img = cv2.imread(str(img_path))                  \n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)       \n    ax.imshow(img)\n    ax.axis(\"off\")\n    ax.set_title(img_path.name, fontsize=20)\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T20:02:11.442672Z","iopub.execute_input":"2025-11-13T20:02:11.443205Z","iopub.status.idle":"2025-11-13T20:02:18.903949Z","shell.execute_reply.started":"2025-11-13T20:02:11.443181Z","shell.execute_reply":"2025-11-13T20:02:18.903011Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Load csv files. No submission file, just train and test.","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/vesuvius-challenge-surface-detection/train.csv')\ntest = pd.read_csv('/kaggle/input/vesuvius-challenge-surface-detection/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:54:07.252509Z","iopub.execute_input":"2025-11-13T19:54:07.253158Z","iopub.status.idle":"2025-11-13T19:54:07.289704Z","shell.execute_reply.started":"2025-11-13T19:54:07.253129Z","shell.execute_reply":"2025-11-13T19:54:07.288808Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.tail()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:54:25.418517Z","iopub.execute_input":"2025-11-13T19:54:25.419089Z","iopub.status.idle":"2025-11-13T19:54:25.450277Z","shell.execute_reply.started":"2025-11-13T19:54:25.419063Z","shell.execute_reply":"2025-11-13T19:54:25.449541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.tail()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T19:54:41.208268Z","iopub.execute_input":"2025-11-13T19:54:41.208616Z","iopub.status.idle":"2025-11-13T19:54:41.216988Z","shell.execute_reply.started":"2025-11-13T19:54:41.208590Z","shell.execute_reply":"2025-11-13T19:54:41.216157Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## And, the only test tif file.","metadata":{}},{"cell_type":"code","source":"def plotImages(tools,directory):\n    print(tools)\n    multipleImages = glob.glob(directory)\n    plt.rcParams['figure.figsize'] = (12, 12) #Original is 15,15. Since we have 18 veggies I decreased the size\n    plt.subplots_adjust(wspace=0, hspace=0)\n    i_ = 0\n    for l in multipleImages[:1]:\n        im = cv2.imread(l)\n        im = cv2.resize(im, (256, 256)) \n        plt.subplot(1, 1, i_+1) #.set_title(l)\n        plt.imshow(cv2.cvtColor(im, cv2.COLOR_BGR2RGB)); plt.axis('off')\n        i_ += 1\n\nplotImages(\"Vesuvius Surface Detection test image\",\"../input/vesuvius-challenge-surface-detection/test_images/**\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T21:15:23.481585Z","iopub.execute_input":"2025-11-13T21:15:23.482207Z","iopub.status.idle":"2025-11-13T21:15:24.567115Z","shell.execute_reply.started":"2025-11-13T21:15:23.482171Z","shell.execute_reply":"2025-11-13T21:15:24.566206Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Since it's a Surface Detection, I could't read anything till now.","metadata":{}},{"cell_type":"markdown","source":"### AI deciphered text on ancient scrolls\n\n\"The Herculaneum Papyri, an ancient scroll fossilized by the Mount Vesuvius eruption in 79 AD, is now decipherable, thanks to an open-source AI project.\"\n\n\"Computer science student Luke Farritor \"became the first person in two millennia to see an entire word from within an unopened scroll this August,\" according to the Vesuvius Challenge, which offers cash prizes for those who can figure out what the scroll says. The contest was created to accelerate the research and discovery of the scrolls after University of Kentucky researchers led by Dr. Brent Seales used computer vision to virtually \"open\" the scrolls in 2015.\"\n\n\"Farritor was awarded 40,000 for discovering the first word. Another contestant, biorobotics student Youssef Nader, used another method involving an unsupervised pre-training model on the data, then fine-tuning the data on the \"fragment labels.\" Nader found letters possibly forming the words \"**achieving\"** and \"**similar**\"; he was awarded 10,000 for his discovery.\"\n\nhttps://www.instagram.com/p/Cyo10dSrTMH/\n\n## The real gains are still ahead of us.\n\n\"Some of the papyrus topics discussed by Philodemus and Epicurus are still relevant. “The basic questions Epicurus was asking are the ones that face us all as humans. How do we live a good life? How do we avoid pain?” But **“the real gains are still ahead of us**”\n \n“What’s so exciting is less what this scroll says, but that the decipherment of this scroll bodes well for the decipherment of the hundreds of scrolls that they had previously given up on.\"\n\nhttps://www.scientificamerican.com/article/ai-unravels-ancient-roman-scrolls-charred-by-volcano/#:~:text=Text%20from%20the%20Herculaneum%20scroll,been%20unseen%20for%202%2C000%20years.&text=A%20team%20of%20student%20researchers,the%20eruption%20of%20Mount%20Vesuvius.","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgements:\n\nIhelon https://www.kaggle.com/code/ihelon/illustrations-kumapi390-eda\n\nGeorgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\nRuhul Amin https://www.kaggle.com/code/ruhul20/cctv-weapon-detection-yolo11s/notebook","metadata":{}}]}