Skip to content

Commit

Permalink
07-thresholding: Make Juptyer notebook compatible with numpy 1.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
uschille committed Aug 28, 2021
1 parent da8fc38 commit 328d544
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions code/07-thresholding/07-thresholding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,33 @@
"import skimage.io\n",
"import skimage.color\n",
"import skimage.filters\n",
"%matplotlib inline"
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df336644",
"id": "8f326e0f-a934-4c03-b0a1-b5e3ce0457e2",
"metadata": {},
"outputs": [],
"source": [
"%load_ext watermark\n",
"%watermark -v -p numpy,matplotlib,skimage\n",
"%matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c04650e",
"metadata": {},
"outputs": [],
"source": [
"# load the image\n",
"image = skimage.io.imread(\"../../fig/06-junk-before.jpg\")\n",
"\n",
"skimage.io.imshow(image)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(image)\n",
"plt.show()"
]
},
Expand All @@ -55,7 +68,8 @@
"# convert the image to grayscale\n",
"gray_image = skimage.color.rgb2gray(image)\n",
"\n",
"skimage.io.imshow(gray_image)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(gray_image, cmap='gray')\n",
"plt.show()"
]
},
Expand All @@ -69,6 +83,7 @@
"# create a histogram of the blurred grayscale image\n",
"histogram, bin_edges = np.histogram(gray_image, bins=256, range=(0.0, 1.0))\n",
"\n",
"fig, ax = plt.subplots()\n",
"plt.plot(bin_edges[0:-1], histogram)\n",
"plt.title(\"Grayscale Histogram\")\n",
"plt.xlabel(\"grayscale value\")\n",
Expand All @@ -87,7 +102,8 @@
"t = 0.8\n",
"binary_mask = gray_image < t\n",
"\n",
"skimage.io.imshow(binary_mask)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(binary_mask, cmap='gray')\n",
"plt.show()"
]
},
Expand All @@ -102,7 +118,8 @@
"selection = np.zeros_like(image)\n",
"selection[binary_mask] = image[binary_mask]\n",
"\n",
"skimage.io.imshow(selection)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(selection)\n",
"plt.show()"
]
},
Expand All @@ -125,6 +142,7 @@
"gray_image = skimage.color.rgb2gray(image)\n",
"histogram, bin_edges = np.histogram(gray_image, bins=256, range=(0.0, 1.0))\n",
"\n",
"fig, ax = plt.subplots()\n",
"plt.plot(bin_edges[0:-1], histogram)\n",
"plt.title(\"Graylevel histogram\")\n",
"plt.xlabel(\"gray value\")\n",
Expand All @@ -143,7 +161,8 @@
"t = 0.5\n",
"binary_mask = gray_image > t\n",
"\n",
"skimage.io.imshow(binary_mask)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(binary_mask, cmap='gray')\n",
"plt.show()"
]
},
Expand All @@ -157,7 +176,8 @@
"selection = np.zeros_like(image)\n",
"selection[binary_mask] = image[binary_mask]\n",
"\n",
"skimage.io.imshow(selection)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(selection)\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -188,6 +208,7 @@
"# create the histogram\n",
"histogram, bin_edges = np.histogram(blurred_image, bins=256, range=(0.0, 1.0))\n",
"\n",
"fig, ax = plt.subplots()\n",
"plt.plot(bin_edges[0:-1], histogram)\n",
"plt.title(\"Graylevel histogram\")\n",
"plt.xlabel(\"gray value\")\n",
Expand Down Expand Up @@ -218,7 +239,8 @@
"# perform adaptive thresholding\n",
"binary_mask = blurred_image > t\n",
"\n",
"skimage.io.imshow(binary_mask)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(binary_mask, cmap='gray')\n",
"plt.show()"
]
},
Expand All @@ -233,7 +255,8 @@
"selection = np.zeros_like(image)\n",
"selection[binary_mask] = image[binary_mask]\n",
"\n",
"skimage.io.imshow(selection)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(selection)\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -376,6 +399,7 @@
"\n",
"histogram, bin_edges = np.histogram(blurred_image, bins=256, range=(0.0, 1.0))\n",
"\n",
"fig, ax = plt.subplots()\n",
"plt.plot(bin_edges[0:-1], histogram)\n",
"plt.title(\"Graylevel histogram\")\n",
"plt.xlabel(\"gray value\")\n",
Expand All @@ -394,7 +418,8 @@
"t = 0.2\n",
"binary_mask = blurred_image < t\n",
"\n",
"skimage.io.imshow(binary_mask)\n",
"fig, ax = plt.subplots()\n",
"plt.imshow(binary_mask, cmap='gray')\n",
"plt.show()"
]
}
Expand Down

0 comments on commit 328d544

Please sign in to comment.