{"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"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nfrom PIL import Image\nfrom IPython.display import clear_output\nimport time\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport ipywidgets as widgets\nfrom IPython.display import display\nfrom ipywidgets import interact\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-20T15:03:08.003458Z","iopub.execute_input":"2023-04-20T15:03:08.004050Z","iopub.status.idle":"2023-04-20T15:03:08.010678Z","shell.execute_reply.started":"2023-04-20T15:03:08.003997Z","shell.execute_reply":"2023-04-20T15:03:08.009395Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# About\n\n**This notebook plots the histograms of each .tif file for each object. Hopefully this will allow the viewer to understand more about the distribution of each object. Scrollbars are presented above each viewer.**","metadata":{}},{"cell_type":"code","source":"folder_paths = [\n    '/kaggle/input/vesuvius-challenge-ink-detection/train/1/surface_volume/',\n    '/kaggle/input/vesuvius-challenge-ink-detection/train/2/surface_volume/',\n    '/kaggle/input/vesuvius-challenge-ink-detection/train/3/surface_volume/',\n    '/kaggle/input/vesuvius-challenge-ink-detection/test/a/surface_volume/',\n    '/kaggle/input/vesuvius-challenge-ink-detection/test/b/surface_volume/']\n","metadata":{"execution":{"iopub.status.busy":"2023-04-20T15:03:08.013225Z","iopub.execute_input":"2023-04-20T15:03:08.014153Z","iopub.status.idle":"2023-04-20T15:03:08.022435Z","shell.execute_reply.started":"2023-04-20T15:03:08.014091Z","shell.execute_reply":"2023-04-20T15:03:08.021422Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_tiff_files(folder_path):\n    filenames = sorted(os.listdir(folder_path))\n    tiff_files = [filename for filename in filenames if filename.endswith('.tif')]\n    images = []\n    for tiff_file in tiff_files:\n        file_path = os.path.join(folder_path, tiff_file)\n        image = Image.open(file_path)\n        images.append(image)\n\n    return images","metadata":{"execution":{"iopub.status.busy":"2023-04-20T15:03:08.023994Z","iopub.execute_input":"2023-04-20T15:03:08.024349Z","iopub.status.idle":"2023-04-20T15:03:08.033354Z","shell.execute_reply.started":"2023-04-20T15:03:08.024315Z","shell.execute_reply":"2023-04-20T15:03:08.032405Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def return_image_arrays(imgs):\n    # Convert the image to a NumPy array\n    image_arrays = []\n    for img in imgs:\n        image_array = np.array(img)\n        image_arrays.append(image_array.ravel())\n        \n    return image_arrays","metadata":{"execution":{"iopub.status.busy":"2023-04-20T15:03:08.035773Z","iopub.execute_input":"2023-04-20T15:03:08.036336Z","iopub.status.idle":"2023-04-20T15:03:08.048607Z","shell.execute_reply.started":"2023-04-20T15:03:08.036297Z","shell.execute_reply":"2023-04-20T15:03:08.047710Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_histogram(image_index):\n    image = images[image_index]\n    \n    # Convert the image to a NumPy array\n    image_array = np.array(image)\n\n    # Create a histogram of the pixel values\n    plt.hist(image_array.ravel(), bins=256, range=(image_array.min(), image_array.max()))\n    plt.title(f'Histogram of Pixel Values for Slice {image_index}')\n    plt.xlabel('Pixel Value')\n    plt.ylabel('Frequency')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-20T15:03:08.050396Z","iopub.execute_input":"2023-04-20T15:03:08.051147Z","iopub.status.idle":"2023-04-20T15:03:08.061406Z","shell.execute_reply.started":"2023-04-20T15:03:08.051106Z","shell.execute_reply":"2023-04-20T15:03:08.060330Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train 1","metadata":{}},{"cell_type":"code","source":"images = load_tiff_files(folder_paths[0])\nimage_arrays = return_image_arrays(images)\n\n# Create a slider for the image indices\nimage_index_slider = widgets.IntSlider(min=0, max=len(images) - 1, step=1, value=0, description='Slice Index')\n\n# Display the interactive plot\ninteract(plot_histogram, image_index=image_index_slider)","metadata":{"execution":{"iopub.status.busy":"2023-04-20T15:03:08.063108Z","iopub.execute_input":"2023-04-20T15:03:08.064106Z","iopub.status.idle":"2023-04-20T15:03:36.614687Z","shell.execute_reply.started":"2023-04-20T15:03:08.064069Z","shell.execute_reply":"2023-04-20T15:03:36.613368Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train 2","metadata":{}},{"cell_type":"code","source":"images = load_tiff_files(folder_paths[1])\nimage_arrays = return_image_arrays(images)\n\n# Create a slider for the image indices\nimage_index_slider = widgets.IntSlider(min=0, max=len(images) - 1, step=1, value=0, description='Slice Index')\n\n# Display the interactive plot\ninteract(plot_histogram, image_index=image_index_slider)","metadata":{"_kg_hide-input":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train 3","metadata":{}},{"cell_type":"code","source":"images = load_tiff_files(folder_paths[2])\nimage_arrays = return_image_arrays(images)\n\n# Create a slider for the image indices\nimage_index_slider = widgets.IntSlider(min=0, max=len(images) - 1, step=1, value=0, description='Slice Index')\n\n# Display the interactive plot\ninteract(plot_histogram, image_index=image_index_slider)","metadata":{"_kg_hide-input":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test A","metadata":{}},{"cell_type":"code","source":"images = load_tiff_files(folder_paths[3])\nimage_arrays = return_image_arrays(images)\n\n# Create a slider for the image indices\nimage_index_slider = widgets.IntSlider(min=0, max=len(images) - 1, step=1, value=0, description='Slice Index')\n\n# Display the interactive plot\ninteract(plot_histogram, image_index=image_index_slider)","metadata":{"_kg_hide-input":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test B","metadata":{}},{"cell_type":"code","source":"images = load_tiff_files(folder_paths[4])\nimage_arrays = return_image_arrays(images)\n\n# Create a slider for the image indices\nimage_index_slider = widgets.IntSlider(min=0, max=len(images) - 1, step=1, value=0, description='Slice Index')\n\n# Display the interactive plot\ninteract(plot_histogram, image_index=image_index_slider)","metadata":{"_kg_hide-input":true},"execution_count":null,"outputs":[]}]}