Skip to content

Commit

Permalink
Add entry-level function
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Aug 25, 2023
1 parent 3389ea4 commit bc8b8c8
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion isic-superpixel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,37 @@
" return superpixel_labels"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6aab4ef1-49f4-4146-a86b-7806ce47b8b5",
"metadata": {},
"outputs": [],
"source": [
"def superpixels(filename, variant=1) -> np.ndarray:\n",
" \"\"\"\n",
" Segment an image in the file into super-pixels. Variants:\n",
" 1=old implementation\n",
" 2=old implementation with bigger superpixels\n",
" 3=new implementation (with bigger superpixels) using texture\n",
" 4=new implementation (with bigger superpixels) using texture with scikit-image SLIC\n",
" \"\"\"\n",
" if variant == 1:\n",
" image = ISICSuperpixelV2.load_image(filename)\n",
" return ISICSuperpixelV2._slic(image, num_segments=1000)\n",
" elif variant == 2:\n",
" image = ISICSuperpixelV2.load_image(filename)\n",
" return ISICSuperpixelV2._slic(image, num_segments=300)\n",
" elif variant == 3:\n",
" image = itk.imread(filename)\n",
" return ISICSuperpixelV3._slic(image, num_segments=300, slic_zero=False)\n",
" elif variant == 4:\n",
" image = itk.imread(filename)\n",
" return ISICSuperpixelV3._slic(image, num_segments=300, slic_zero=True)\n",
" else:\n",
" raise ValueError"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -288,7 +319,8 @@
"image_file = image_list[0]\n",
"image_file = \"./images/ISIC_0016085.JPG\"\n",
"image = ISICSuperpixelV2.load_image(image_file)\n",
"superpixel_labels = ISICSuperpixelV2._slic(image, num_segments=300)"
"superpixel_labels = ISICSuperpixelV2._slic(image, num_segments=300)\n",
"superpixel_labels = superpixels(image_file, 4)"
]
},
{
Expand Down

0 comments on commit bc8b8c8

Please sign in to comment.