|
5 | 5 | "id": "335897f5", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# Image Pixelization / De-Pixelization Demo" |
| 8 | + "# Image Pixelization / De-Pixelization Demo\n", |
| 9 | + "\n", |
| 10 | + "This notebook demonstrates how to create a pixelated animation from an original image and then attempt to reconstruct an image from these pixelated blocks.\\\n", |
| 11 | + "The pixelation effect is achieved using a `nearest` neighbor filter during downsampling and upsampling of a moving window.\n" |
9 | 12 | ] |
10 | 13 | }, |
11 | 14 | { |
|
18 | 21 | }, |
19 | 22 | { |
20 | 23 | "cell_type": "code", |
21 | | - "execution_count": 1, |
| 24 | + "execution_count": 9, |
22 | 25 | "id": "20f4dbc1", |
23 | 26 | "metadata": {}, |
24 | 27 | "outputs": [ |
|
29 | 32 | "<PIL.Image.Image image mode=RGBA size=380x380>" |
30 | 33 | ] |
31 | 34 | }, |
32 | | - "execution_count": 1, |
| 35 | + "execution_count": 9, |
33 | 36 | "metadata": {}, |
34 | 37 | "output_type": "execute_result" |
35 | 38 | } |
|
55 | 58 | }, |
56 | 59 | { |
57 | 60 | "cell_type": "code", |
58 | | - "execution_count": 2, |
| 61 | + "execution_count": 10, |
59 | 62 | "id": "d3ba5abf", |
60 | 63 | "metadata": {}, |
61 | 64 | "outputs": [ |
|
114 | 117 | }, |
115 | 118 | { |
116 | 119 | "cell_type": "code", |
117 | | - "execution_count": 3, |
| 120 | + "execution_count": null, |
118 | 121 | "id": "82f5e2d1", |
119 | 122 | "metadata": {}, |
120 | 123 | "outputs": [ |
|
6138 | 6141 | "<IPython.core.display.HTML object>" |
6139 | 6142 | ] |
6140 | 6143 | }, |
6141 | | - "execution_count": 3, |
| 6144 | + "execution_count": 11, |
6142 | 6145 | "metadata": {}, |
6143 | 6146 | "output_type": "execute_result" |
6144 | 6147 | } |
|
6160 | 6163 | " ...,\n", |
6161 | 6164 | " y_start:y_end,\n", |
6162 | 6165 | " x_start:x_end\n", |
6163 | | - " ] = F.interpolate(original[\n", |
6164 | | - " ...,\n", |
6165 | | - " y_start:y_end:CHUNK_SIZE,\n", |
6166 | | - " x_start:x_end:CHUNK_SIZE\n", |
6167 | | - " ], size=(AREA_SIZE, AREA_SIZE), mode='nearest')\n", |
| 6166 | + " ] = F.interpolate(\n", |
| 6167 | + " F.interpolate(\n", |
| 6168 | + " original[\n", |
| 6169 | + " ...,\n", |
| 6170 | + " y_start:y_end,\n", |
| 6171 | + " x_start:x_end\n", |
| 6172 | + " ],\n", |
| 6173 | + " size=(AREA_SIZE // CHUNK_SIZE, AREA_SIZE // CHUNK_SIZE),\n", |
| 6174 | + " mode='nearest' # use NEAREST-FILTER\n", |
| 6175 | + " ),\n", |
| 6176 | + " size=(AREA_SIZE, AREA_SIZE),\n", |
| 6177 | + " mode='nearest'\n", |
| 6178 | + " )\n", |
6168 | 6179 | "\n", |
6169 | 6180 | "def display_frames(title, frames):\n", |
6170 | 6181 | " fig, ax = plt.subplots()\n", |
6171 | 6182 | " ims = []\n", |
6172 | 6183 | " for frame in frames:\n", |
6173 | | - " # Assuming 'frame[0]' is your image data that can be processed by TF.to_pil_image\n", |
6174 | 6184 | " pil_image = TF.to_pil_image(TF.vflip(frame))\n", |
6175 | | - " # Append the image object returned by imshow to the list\n", |
6176 | 6185 | " im_artist = ax.imshow(pil_image, animated=True)\n", |
6177 | | - " ims.append([im_artist]) # ims should be a list of lists of artists\n", |
| 6186 | + " ims.append([im_artist])\n", |
6178 | 6187 | "\n", |
6179 | 6188 | " import matplotlib.animation as animation\n", |
6180 | 6189 | " ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, repeat_delay=1000)\n", |
|
6208 | 6217 | }, |
6209 | 6218 | { |
6210 | 6219 | "cell_type": "code", |
6211 | | - "execution_count": 4, |
| 6220 | + "execution_count": 12, |
6212 | 6221 | "id": "a956c6f5", |
6213 | 6222 | "metadata": {}, |
6214 | 6223 | "outputs": [ |
|
8121 | 8130 | "<IPython.core.display.HTML object>" |
8122 | 8131 | ] |
8123 | 8132 | }, |
8124 | | - "execution_count": 4, |
| 8133 | + "execution_count": 12, |
8125 | 8134 | "metadata": {}, |
8126 | 8135 | "output_type": "execute_result" |
8127 | 8136 | } |
|
8158 | 8167 | }, |
8159 | 8168 | { |
8160 | 8169 | "cell_type": "code", |
8161 | | - "execution_count": 7, |
| 8170 | + "execution_count": 13, |
8162 | 8171 | "id": "276d5775", |
8163 | 8172 | "metadata": {}, |
8164 | 8173 | "outputs": [ |
|
8169 | 8178 | "<PIL.Image.Image image mode=RGBA size=380x380>" |
8170 | 8179 | ] |
8171 | 8180 | }, |
8172 | | - "execution_count": 7, |
| 8181 | + "execution_count": 13, |
8173 | 8182 | "metadata": {}, |
8174 | 8183 | "output_type": "execute_result" |
8175 | 8184 | } |
|
8194 | 8203 | }, |
8195 | 8204 | { |
8196 | 8205 | "cell_type": "code", |
8197 | | - "execution_count": 8, |
| 8206 | + "execution_count": 14, |
8198 | 8207 | "id": "24bb6abb", |
8199 | 8208 | "metadata": {}, |
8200 | 8209 | "outputs": [ |
|
8205 | 8214 | "<PIL.Image.Image image mode=RGBA size=380x380>" |
8206 | 8215 | ] |
8207 | 8216 | }, |
8208 | | - "execution_count": 8, |
| 8217 | + "execution_count": 14, |
8209 | 8218 | "metadata": {}, |
8210 | 8219 | "output_type": "execute_result" |
8211 | 8220 | } |
|
0 commit comments