|
45 | 45 | "cell_type": "code", |
46 | 46 | "execution_count": null, |
47 | 47 | "metadata": { |
48 | | - "id": "gxbHBsF-8Y_l" |
| 48 | + "colab": { |
| 49 | + "base_uri": "https://localhost:8080/" |
| 50 | + }, |
| 51 | + "id": "gxbHBsF-8Y_l", |
| 52 | + "outputId": "6811bf9d-8d70-4311-878e-165a3742b65b" |
49 | 53 | }, |
50 | 54 | "outputs": [], |
51 | 55 | "source": [ |
|
72 | 76 | }, |
73 | 77 | { |
74 | 78 | "cell_type": "code", |
75 | | - "execution_count": null, |
| 79 | + "execution_count": 2, |
76 | 80 | "metadata": { |
77 | 81 | "id": "OMjuVQiDYJKF" |
78 | 82 | }, |
|
102 | 106 | }, |
103 | 107 | { |
104 | 108 | "cell_type": "code", |
105 | | - "execution_count": null, |
| 109 | + "execution_count": 3, |
106 | 110 | "metadata": { |
107 | 111 | "id": "9gYTyXhTKy3H" |
108 | 112 | }, |
|
142 | 146 | }, |
143 | 147 | { |
144 | 148 | "cell_type": "code", |
145 | | - "execution_count": null, |
| 149 | + "execution_count": 4, |
146 | 150 | "metadata": { |
147 | 151 | "id": "tzXuqyIBlXer" |
148 | 152 | }, |
|
178 | 182 | "cell_type": "code", |
179 | 183 | "execution_count": null, |
180 | 184 | "metadata": { |
181 | | - "id": "8rjHk72-lmHX" |
| 185 | + "colab": { |
| 186 | + "base_uri": "https://localhost:8080/", |
| 187 | + "height": 274 |
| 188 | + }, |
| 189 | + "id": "8rjHk72-lmHX", |
| 190 | + "outputId": "5269c698-f813-445b-b802-eae563a0d270" |
182 | 191 | }, |
183 | 192 | "outputs": [], |
184 | 193 | "source": [ |
|
220 | 229 | }, |
221 | 230 | { |
222 | 231 | "cell_type": "code", |
223 | | - "execution_count": null, |
| 232 | + "execution_count": 6, |
224 | 233 | "metadata": { |
225 | 234 | "id": "hl6ojNjl4i6o" |
226 | 235 | }, |
|
234 | 243 | "cell_type": "code", |
235 | 244 | "execution_count": null, |
236 | 245 | "metadata": { |
237 | | - "id": "Yl_Oiye4mUuo" |
| 246 | + "colab": { |
| 247 | + "base_uri": "https://localhost:8080/", |
| 248 | + "height": 274 |
| 249 | + }, |
| 250 | + "id": "Yl_Oiye4mUuo", |
| 251 | + "outputId": "48829df3-56d8-4766-b012-4f458c11e7a4" |
238 | 252 | }, |
239 | 253 | "outputs": [], |
240 | 254 | "source": [ |
|
254 | 268 | "\n", |
255 | 269 | "# Create the options that will be used for InteractiveSegmenter\n", |
256 | 270 | "base_options = python.BaseOptions(model_asset_path='model.tflite')\n", |
257 | | - "options = vision.ImageSegmenterOptions(base_options=base_options,\n", |
| 271 | + "options = vision.InteractiveSegmenterOptions(base_options=base_options,\n", |
258 | 272 | " output_category_mask=True)\n", |
259 | 273 | "\n", |
260 | 274 | "# Create the interactive segmenter\n", |
|
279 | 293 | " bg_image = np.zeros(image_data.shape, dtype=np.uint8)\n", |
280 | 294 | " bg_image[:] = BG_COLOR\n", |
281 | 295 | "\n", |
282 | | - " condition = np.stack((category_mask.numpy_view(),) * 3, axis=-1) > 0.1\n", |
283 | | - " output_image = np.where(condition, fg_image, bg_image)\n", |
| 296 | + " condition = category_mask.numpy_view().squeeze(-1) > 0.1\n", |
| 297 | + " output_image = np.where(condition[..., None], fg_image, bg_image)\n", |
284 | 298 | "\n", |
285 | 299 | " # Draw a white dot with black border to denote the point of interest\n", |
286 | 300 | " thickness, radius = 6, -1\n", |
|
305 | 319 | "cell_type": "code", |
306 | 320 | "execution_count": null, |
307 | 321 | "metadata": { |
308 | | - "id": "ciCGwCQ3gNDc" |
| 322 | + "colab": { |
| 323 | + "base_uri": "https://localhost:8080/", |
| 324 | + "height": 274 |
| 325 | + }, |
| 326 | + "id": "ciCGwCQ3gNDc", |
| 327 | + "outputId": "8d903a0d-11b6-48a3-f85c-b2ee1c2eea65" |
309 | 328 | }, |
310 | 329 | "outputs": [], |
311 | 330 | "source": [ |
|
332 | 351 | " # Apply effects\n", |
333 | 352 | " blurred_image = cv2.GaussianBlur(image_data, (55,55), 0)\n", |
334 | 353 | " condition = np.stack((category_mask.numpy_view(),) * 3, axis=-1) > 0.1\n", |
335 | | - " output_image = np.where(condition, image_data, blurred_image)\n", |
| 354 | + " condition = category_mask.numpy_view().squeeze(-1) > 0.1\n", |
| 355 | + " output_image = np.where(condition[..., None], image_data, blurred_image)\n", |
336 | 356 | "\n", |
337 | 357 | " # Draw a white dot with black border to denote the point of interest\n", |
338 | 358 | " thickness, radius = 6, -1\n", |
|
357 | 377 | "cell_type": "code", |
358 | 378 | "execution_count": null, |
359 | 379 | "metadata": { |
360 | | - "id": "szFMEFuymrHd" |
| 380 | + "colab": { |
| 381 | + "base_uri": "https://localhost:8080/", |
| 382 | + "height": 274 |
| 383 | + }, |
| 384 | + "id": "szFMEFuymrHd", |
| 385 | + "outputId": "6fdc6af9-dc91-4b67-eea6-d23fee03837a" |
361 | 386 | }, |
362 | 387 | "outputs": [], |
363 | 388 | "source": [ |
|
386 | 411 | " overlay_image[:] = OVERLAY_COLOR\n", |
387 | 412 | "\n", |
388 | 413 | " # Create the condition from the category_masks array\n", |
389 | | - " alpha = np.stack((category_mask.numpy_view(),) * 3, axis=-1) > 0.1\n", |
| 414 | + " alpha = category_mask.numpy_view().squeeze(-1) > 0.1\n", |
| 415 | + " alpha = alpha[..., None]\n", |
390 | 416 | "\n", |
391 | 417 | " # Create an alpha channel from the condition with the desired opacity (e.g., 0.7 for 70%)\n", |
392 | 418 | " alpha = alpha.astype(float) * 0.7\n", |
|
0 commit comments