{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Convert `.mat`\n", "Converts Camera Signal and Radiant Temperature of `.mat` files to `.p` filetype." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import imageio\n", "import numpy as np\n", "import pickle\n", "import scipy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "folder = \"powder_plate_7_bare_pad_195_w_800_mm_s\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(501, 127, 360)\n", "16367\n" ] } ], "source": [ "filename = \"camera_signal\"\n", "\n", "mat = scipy.io.loadmat(f\"data/{folder}/{filename}.mat\")\n", "video = mat[\"CameraSignal\"]\n", "\n", "# Reshapes from (y, x, f) to (f, x, y)\n", "video_reshaped = np.transpose(video, (2, 0, 1))\n", "print(video_reshaped.shape)\n", "print(np.max(video_reshaped))\n", "\n", "with open(f\"data/{folder}/{filename}.pkl\", \"wb\") as file:\n", " pickle.dump(video_reshaped, file)\n", "\n", "# Normalizes the video for visual output\n", "video_normalized = np.interp(\n", " video_reshaped,\n", " (video_reshaped.min(), video_reshaped.max()),\n", " (0, 255)\n", ")\n", "\n", "frames = []\n", "for frame in video_normalized:\n", " frames.append(frame)\n", "\n", "imageio.mimsave(f\"data/{folder}/{filename}.gif\", frames)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(501, 127, 360)\n", "1073.1382220207333\n" ] } ], "source": [ "filename = \"radiant_temperature\"\n", "\n", "mat = scipy.io.loadmat(f\"data/{folder}/{filename}.mat\")\n", "video = mat[\"RadiantTemperature\"]\n", "\n", "# Reshapes from (x, y, f) to (f, x, y)\n", "video_reshaped = np.transpose(video, (2, 0, 1))\n", "print(video_reshaped.shape)\n", "print(np.max(video_reshaped))\n", "\n", "with open(f\"data/{folder}/{filename}.pkl\", \"wb\") as file:\n", " pickle.dump(video_reshaped, file)\n", "\n", "# Normalizes the video for visual output\n", "video_normalized = np.interp(\n", " video_reshaped,\n", " (video_reshaped.min(), video_reshaped.max()),\n", " (0, 255)\n", ")\n", "\n", "frames = []\n", "for frame in video_normalized:\n", " frames.append(frame)\n", "\n", "imageio.mimsave(f\"data/{folder}/{filename}.gif\", frames)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }