Spaces:
Runtime error
Runtime error
Sagar Bharadwaj
commited on
Commit
·
804cbcd
1
Parent(s):
54cb6c5
Updated notebook example
Browse files- ColorByNumber.ipynb +34 -16
ColorByNumber.ipynb
CHANGED
|
@@ -3,14 +3,12 @@
|
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
"execution_count": null,
|
| 6 |
-
"id": "
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [],
|
| 9 |
"source": [
|
| 10 |
-
"import
|
| 11 |
-
"
|
| 12 |
-
"from colorbynumber.utils import show_image\n",
|
| 13 |
-
"from colorbynumber.simplify_image import simplify_image"
|
| 14 |
]
|
| 15 |
},
|
| 16 |
{
|
|
@@ -23,25 +21,45 @@
|
|
| 23 |
"# Image from: https://www.pexels.com/photo/scarlet-macaw-1618424/\n",
|
| 24 |
"# Photographer: Tim Mossholder\n",
|
| 25 |
"\n",
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
]
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
"execution_count": null,
|
| 34 |
-
"id": "
|
| 35 |
"metadata": {},
|
| 36 |
"outputs": [],
|
| 37 |
"source": [
|
| 38 |
-
"
|
| 39 |
-
" (255, 0, 0), # Red\n",
|
| 40 |
-
" (0, 255, 0), # Green\n",
|
| 41 |
-
" (0, 0, 255), # Blue\n",
|
| 42 |
-
"]\n",
|
| 43 |
-
"simplified_image = simplify_image(image, color_list)\n",
|
| 44 |
-
"show_image(simplified_image)"
|
| 45 |
]
|
| 46 |
}
|
| 47 |
],
|
|
|
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
"execution_count": null,
|
| 6 |
+
"id": "44153707-a329-46d4-8eda-d0ffe1304999",
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [],
|
| 9 |
"source": [
|
| 10 |
+
"from colorbynumber.main import ColorByNumber\n",
|
| 11 |
+
"from colorbynumber import utils"
|
|
|
|
|
|
|
| 12 |
]
|
| 13 |
},
|
| 14 |
{
|
|
|
|
| 21 |
"# Image from: https://www.pexels.com/photo/scarlet-macaw-1618424/\n",
|
| 22 |
"# Photographer: Tim Mossholder\n",
|
| 23 |
"\n",
|
| 24 |
+
"image_path = \"ExampleImages/Macaw.jpeg\"\n",
|
| 25 |
+
"color_list = [\n",
|
| 26 |
+
" (255, 5, 0), # Red\n",
|
| 27 |
+
" (2, 94, 3), # Dark Green\n",
|
| 28 |
+
" (0, 0, 255), # Blue\n",
|
| 29 |
+
" (216, 235, 52), # Yellow\n",
|
| 30 |
+
" (0,0,0), # Black\n",
|
| 31 |
+
" (255, 255, 255), # White\n",
|
| 32 |
+
"]\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"config = {\n",
|
| 35 |
+
" \"denoise\": True,\n",
|
| 36 |
+
" \"denoise_h\": 100,\n",
|
| 37 |
+
" \"border_padding\": 2,\n",
|
| 38 |
+
" \"area_perc_threshold\": 0.5,\n",
|
| 39 |
+
" \"arc_length_area_ratio_threshold\": 1,\n",
|
| 40 |
+
" \"border_color\": (0, 0, 0),\n",
|
| 41 |
+
" \"font_size\": 0.5,\n",
|
| 42 |
+
" \"font_color\": (0, 0, 0),\n",
|
| 43 |
+
" \"font_thickness\": 1,\n",
|
| 44 |
+
"}\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"colorbynumber_obj = ColorByNumber(\n",
|
| 47 |
+
" image_path = image_path, \n",
|
| 48 |
+
" color_list = color_list,\n",
|
| 49 |
+
" config = config,\n",
|
| 50 |
+
")\n",
|
| 51 |
+
"numbered_islands = colorbynumber_obj.create_color_by_number()\n",
|
| 52 |
+
"utils.show_image(numbered_islands, cmap = 'grey')"
|
| 53 |
]
|
| 54 |
},
|
| 55 |
{
|
| 56 |
"cell_type": "code",
|
| 57 |
"execution_count": null,
|
| 58 |
+
"id": "b278a3ff-907b-43db-b7c8-c84803a4c1a7",
|
| 59 |
"metadata": {},
|
| 60 |
"outputs": [],
|
| 61 |
"source": [
|
| 62 |
+
"utils.save_image(numbered_islands, \"Macaw_with_numbers_05_perc.png\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
]
|
| 64 |
}
|
| 65 |
],
|