File size: 3,392 Bytes
8f5cac6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
 "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
}