{"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 tifffile as tiff\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport matplotlib.colors as colors\nfrom skimage import io, color\nimport numpy as np\nfrom tqdm import tqdm\nimport glob\nimport os\nimport cv2\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-20T13:41:04.697015Z","iopub.execute_input":"2023-03-20T13:41:04.697576Z","iopub.status.idle":"2023-03-20T13:41:05.148561Z","shell.execute_reply.started":"2023-03-20T13:41:04.697527Z","shell.execute_reply":"2023-03-20T13:41:05.146841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ","metadata":{}},{"cell_type":"code","source":"samples = [1,2,3]\n\nfor sample in samples:\n    # Load the Mask image\n    ink_image = mpimg.imread(f\"/kaggle/input/vesuvius-challenge-ink-detection/train/{sample}/inklabels.png\")\n    # Get a list of all .tif files in the directory\n    tiff_files = glob.glob(f\"/kaggle/input/vesuvius-challenge-ink-detection/train/{sample}/surface_volume/*.tif\")\n    tiff_file_names = [os.path.basename(file) for file in tiff_files]\n    directory = f\"/kaggle/input/vesuvius-challenge-ink-detection/train/{sample}/surface_volume/\"\n    tiff_files.sort()\n    # Get the first TIFF file to use as a template for video properties\n    template = cv2.imread(tiff_files[0], cv2.IMREAD_COLOR)\n    height, width, layers = template.shape\n    # Define video codec and create VideoWriter object\n    fourcc = cv2.VideoWriter_fourcc(*'mp4v')\n    output_filename = f\"output_video_{str(sample)}.mp4\"\n    video = cv2.VideoWriter(output_filename, fourcc, 5, (width,height))\n    for file in tqdm(tiff_files):\n        # Load the TIFF image\n        image = cv2.imread(file, cv2.IMREAD_COLOR)\n        norm = colors.Normalize(vmin=0, vmax=65535)\n        gray_image_norm = norm(image)\n        masked_image = np.zeros_like(image)\n        masked_image[ink_image[:,:,0] == 1] = gray_image_norm[ink_image[:,:,0] == 1]\n        #plt.imshow(masked_image)\n        #plt.show()\n        video.write(masked_image)\n    video.release()\n","metadata":{"execution":{"iopub.status.busy":"2023-03-20T13:41:05.18369Z","iopub.execute_input":"2023-03-20T13:41:05.184222Z"},"trusted":true},"execution_count":null,"outputs":[]}]}