505 lines
878 KiB
Plaintext
505 lines
878 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Bean counting using connected components and more to do multiple object detection\n",
|
||
|
"\n",
|
||
|
"Now we have an image of many coffee beans and we want to count the number of coffee beans in the image."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"import scipy.misc\n",
|
||
|
"from scipy import ndimage\n",
|
||
|
"import imageio.v2 as imageio"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"im_rgb = imageio.imread('data/IMG_4272.JPG')\n",
|
||
|
"original_gray = im_rgb[:,:,1] # take green channel to make grayscale image"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh0AAAGOCAYAAAAzerGXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOy9eZBkV3Um/mVtWVl7V2/Vm7pb6tbaEhKS0IJ2IQmBABvGwuAJDw5mggkWjwwEHkxMWDj8EwF/ABF4TAQzDNg4MB7HmAGPNwTIwiwS0EJ7q6WWeu+qrr0qMytrzfz9UfHd/t6pc19WS90l1P1OREVlvnzvLufee853lntfrlar1ZBRRhlllFFGGWV0mqnh1W5ARhlllFFGG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MCOOUFYvXGOjZ+3Vj3lpn23YCxtzO1v9j7bF9sPncf23hiYsEmOKqdYnvUC6PeFhYXEfKHi9TwH2g5dk5bseGl7+YzOOe2vXV+eHLF1xWSWld2x/1q2rd+TNwBQLBZx8cUXY2JiAl1dXW79r5Sol5588slXlLBaLBZx2WWXvey2Dg0NYd26dXj44Ydx0003oVarYePGjbjvvvvwh3/4hwAWvRrr16/HZz/7WXzgAx/AxMQE1q5di2984xt497vfDQA4duwYtmzZgn/8x3/EXXfdtay6f609HaeSrCBRYaiCZTkuNw+YLNeKirXJK/dkfktT0DGEbIWzVRBKacAldj3Wb/3dtlOtHnuPteBi5FliMeVej2IWMMuPWSA298K2N83boUrHJvd5ZdiyYsrDKsc0YKpenVcCOLQtaR4D71l7X8yKTQNvXrm2PXZ
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.imshow(original_gray, cmap='gray')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Let's view our image is pseudocolor. This will be helpful for getting absolute intensity values from the images."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {
|
||
|
"scrolled": true
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh0AAAGOCAYAAAAzerGXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9fZxlRXXvj78PZ58+5/Qz3U330DAwA4NDCEQUv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fOc738mlabVavP71r2dsbIy+vj5e8IIXsHfv3odUlh9p0PHyl7+ca6+9lt/5nd/h/PPP5ytf+Qqf+9znOP300486Dz2oxCRmarCAwz7fIuZEZL0ZpAUpR3PeMhNaMVpF8lAAg52hxkCTBiaSpqgcRXVA3aep0q8349az+CZrK1u5zpZVt4+9Z1G7FCmL9a6NKQgR6TexWa3NQ7MLNr8iBWVBpQYcWqGn5BVqDBhoNiEGGo5GpDyD5AGt5H80Y6eUF7oVvFXqGjhaoKkZkRiDmJqPnC8aP2weuk/INTY/DabWMq3Z9rXtr80jAjCy4/W8uaXZyP+Xa+RYpeGUfq0emJNaEo416yF9rQ6DQwGM5Ew0XrFrsNEFPCJIPe24dElVlUmVR1+r62wBgwCNnG+KBxZLneAPAgG0rOX78ZjLBoOOG2+8kde97nV87Wtf4/rrrydNU57znOewsLCQpXn3u9/NH/7hH/KBD3yAb3zjG2zatIlnP/vZzM3NZWmuuOIKPv3pT/PJT36Sm266ifn
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.imshow(original_gray, cmap='jet')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"One thing we may notice are some very small details in the image which will not help us perform our bean counting task."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"im = ndimage.gaussian_filter(original_gray, sigma=10.0)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGg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eJlQrHAJGoCqBQdF7uhOA6kw6VZKxUuDn189Dhdl7zq7Dj8to6Z8pxabYH2htQOuYuQ8d4/W29ePEi3d3dPPXUU7zxjW9kdXWVVCrF/fffz8c+9jFAqBrJZJJPf/rTvP/972d2dpbNmzfz9a9/nXe84x0AjI2NkU6n+fu//3vuueeeqo69oSfEDzzwAP/pP/0nDh06xL/5N/+GL3/5y7zyyiv85//8n5t6nGo7oZo/tdxXs5WOWgeBWtWZK30jlHuAN7NttQ5Mze4XeXynwUAuX4vBU92n27H1/dRDPNaCcFTqs0awVvd9oySmmu2D2nulfapQB16dQFQ87hoSjnIKBpQSjkoEY8MiQGPmFUPNmZubsy0OhUKEQpW1/dnZWQA6OzsBOHfuHOPj47bAjVAoxJ133snRo0d5//vfz/Hjx1lZWbGtk0ql2LdvH0ePHr02SMc73vEOpqen+eQnP8mFCxfYt28ff//3f8/27dur3odTjvuC9ruOWh+ITg/DZnfsRt9fOTRzoHfbl9uAVEmqXi/o7XC7bxpBNYRjrY7tdvx6CYfTOs1o91oqGtXsv5zK4bYPp3vYiXC4zeDlwFyJaNRKPmB9CUfJ+lcr4Wgi0um07fvDDz/MI488Unab1dVVHnjgAe644w727dsHYLoxOAVunD9/3lynpaWFTZs2lazjFNzhhg1NOgA+8IEP8IEPfKCp+6xnUCuHWmeR1e6rkf2VO49qJNdqUa599eyz2oGrkf2tF650+elKM+BK91Y1ake
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.imshow(im, cmap='jet')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-349688ed72efb990",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Question Part A\n",
|
||
|
"\n",
|
||
|
"We now want to pick a single threshold. Ideally, this will perfectly decompose our image into connected components of coffee beans and a background.\n",
|
||
|
"\n",
|
||
|
"Enter a threshold and describe why you chose this value. Use the variable `threshold`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-6e1c2b89bd8a66f5",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Enter your value here\n",
|
||
|
"threshold=60"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-4590afe7907cebe0",
|
||
|
"locked": false,
|
||
|
"points": 0,
|
||
|
"schema_version": 3,
|
||
|
"solution": true
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"(Here you should describe why you chose your particular threshold value.)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhkAAAGTCAYAAACF2QCoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACOD0lEQVR4nO3dd1hT5/s/8HcSpowgogxBxT0QByiCewBiBVcdqIhbHCiiVtGPdbVSbd17oFjFVStWWxy4RcWB4MAtKKIgihj2Ss7vD3/ka2RlJ5D7dV25rvbkOec8x5Bz7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iIiUL9+fQBASkqKSM6MsWPHIisrC5s3b8acOXNgYmKCXr16YdWqVRKdl8XI+UqDg4Nx/PhxPH36FPr6+nBxccGqVatEmuUYhsGyZcuwc+dOZGRkwMnJCVu2bEGrVq2EZQoKCjB37lwcOnQIeXl56N27N7Zu3Qpra2ux6pGZmQkulyvPSyOEELmrW7cuVqxYgaFDh8LQ0FDkveLiYly8eBEzZ87Es2fP5HI+fX193Lx5E23atJFov4KCAjg5OeH+/ftyqYe64vF4Yo1zkEbJc+nChQswMDCQ+jg5OTno3bu3QusqL3LvLrly5QqmT5+O6OhoREZGori4GG5ubsjJyRGWWb16NdauXYvNmzfjzp07sLCwgKurK7KysoRlAgICEB4ejsOHDyMqKgrZ2dno378/+Hy+vKtMCCEqYWVlhUOHDmHcuHGlAgzgawuHm5sbjhw5Itb4CXGYmZmVmvoojuzsbGRkZMilDppOFd0lqiL3lozvffz4EXXq1MGVK1fQrVs
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"thresholded = (im < threshold).astype(np.uint8)\n",
|
||
|
"plt.imshow(thresholded, cmap='gray')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Now, we are once again going to use [connected components labeling](https://en.wikipedia.org/wiki/Connected-component_labeling) to detect objects in our binary image."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiIAAAGOCAYAAACqgmgiAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly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Y4ZM2Zo0rxPP/2Uxx57rMa5Hp06dWLYsGG0a9eOe++9l8WLF9OyZUveffddq+4nPSJCCHFTagb4WVBOjzpUA3DBYa0R1jt58iSBgdcCSS16Q3766ScOHz7MokWLrK5bp04d7r77bo4cOWJVPQlEhBDipuOH9XNAwpFARCP2Ds2Uqv8JDAw0C0S08MknnxAXF0e7du2srqsoCnv27CE2NtaqepoPzcyYMYO7776bgIAAwsLC6N+/f4WlPYqiYDAYiIyMxM/Pj4SEBA4cOGBWpqioiLFjxxIaGkr9+vXp27cvp06d0rq5QgjhJsKBrsAAIAVIQO2J0DvgXrYMtfjhmLbchFwwWTU/P589e/awZ88eADIyMtizZw8nTpwwlcnLy+Prr7/mqaeeqvQajz/+OJMnTzZ9/dprr/H999/z+++/s2fPHp588kn27NnD6NGjrWqb5oHIxo0bee6559i6dSvr16/HaDSSmJjI5cuXTWXefPNNZs2axZw5c9i+fTsRERH06tWLS5cumcqkpqaybNkyFi5cyObNm8nPzyc5OZnS0lKtmyyEEC7khxp09AHaogYkIUBroGfZofUKFluvJ53otdWOHTto37497du3B2DcuHG0b9+eV155xVRm4cKFKIrCo48+Wuk1Tpw4YZZvJCcnh7/85S+
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"labels, num_labels = ndimage.label(thresholded)\n",
|
||
|
"plt.imshow(labels, cmap='jet')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Detour: erosion and dilation (morphological operations)\n",
|
||
|
"\n",
|
||
|
"Here we will take a small detour to demonstrate some morphological operations. You can read about morphological image processing [here](https://en.wikipedia.org/wiki/Mathematical_morphology).\n",
|
||
|
"\n",
|
||
|
"We will first perform `erosion` 30 times in a row on our thresholded image. What does the erosion do?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhkAAAGTCAYAAACF2QCoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABc00lEQVR4nO3deVxU9f4/8NcwA8M+CggDioi4C5FCKe6houZ6rUQh3LfcLqKl5r1Xs66kV8nKLQ2Xcu3etMwtsdQkNRUlBXdFQQVRxEEEZ4A5vz/8Md9GQFlmZV7Px2MeDznzmXPexwHmxefzOZ8jEgRBABEREZGOWRm7ACIiIqqdGDKIiIhILxgyiIiISC8YMoiIiEgvGDKIiIhILxgyiIiISC8YMoiIiEgvGDKIiIhILxgyiIiISC8YMoiIiEgvGDKIiIhqud9++w39+/eHl5cXRCIRfvjhh5e+5siRIwgKCoKtrS0aN26M1atXV/m4DBlERES13JMnTxAYGIjly5dXqn1aWhrefPNNdO7cGWfPnsWHH36IadOm4fvvv6/ScUW8QRoREZHlEIlE2LlzJwYNGlRhm1mzZmHXrl24ePGiZtvEiRPx559/4vjx45U+lqQmhRIREVHlPX36FCqVqsb7EQQBIpFIa5tUKoVUKq3xvgHg+PHjCAsL09rWq1cvxMfHo6ioCNbW1pXaD0MGERGRATx9+hS+vr7Iysqq8b4cHR2Rn5+vtW3evHmYP39+jfcNAFlZWfDw8NDa5uHhgeLiYjx48ACenp6V2g9DBhERkQGoVCpkZWUhPT0dzs7O1d5PXl4eGjZsiIyMDK396KoXo9TzPSWlsyue3/4iDBlEREQG5OzsXKOQoev9lEcul5fpccnOzoZEIoGrq2ul98OQQUREZECCIKAm11wY4nqNkJAQ/PTTT1rbDhw4gODg4ErPxwB4CSsREZFBlYaM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IICIiMjBDr9oZHh6OnJwcLFiwAJmZmfD398fevXvh4+MDAMjMzNRaM2PkyJF4/Pgxli9fjhkzZqBOnToIDQ3FokWLqnRcnQ+XxMbG4rXXXoOTkxPc3d0xaNAgXL58WauNIAiYP38+vLy8YGdnh27duiE1NVWrjVKpxNSpU+Hm5gYHBwcMGDAAt2/f1nW5RET0/wUHB6Nfv34VTgYk8zZp0iTcvHkTSqUSSUlJ6NKli+a5DRs24PDhw1rtp06ditTUVBQUFODu3bvYtGkT6tevX6Vj6jxkHDlyBJMnT8aJEyeQkJCA4uJihIWF4cmTJ5o2ixcvRlxcHJYvX45Tp05BLpejZ8+eePz4saZNdHQ0du7ciW3btiExMRH5+fno168fSkpKdF0yEZHFE4lEmD17NoYPH86QoWfGWIzLWHQ+XLJ//36tr9evXw93d3dNahIEAcuWLcPcuXMxePBgAMDGjRvh4eGBLVu2YMKECVAoFIiPj8e3336LHj16AAA2bdoEb29vHDx4EL169dJ12UREFs3W1haNGzfG77//DrVabexyajXeIE2HFAoFAMDFxQUAkJaWhqysLK2Vx6RSKbp27apZeSwpKQlFRUVabby8vODv71/h6mRKpbLM6mdERFQ5YrEYzs7OKCoqMnYpVIvoNWQIgoCYmBh06tQJ/v7+AKC5TvdFK49lZWXBxsYGdevWrbDN82JjY7VWPvP29tb16RAR1WolJSU4f/68scuo9SxpuESvIWPKlCk4d+4ctm7dWua5qqw8Vpk2c+bMgUKh0DwyMjKqXzgRkZH4+flh1qxZcHd3N+hxCwoKcOnSJVy9etWgx7VEDBk6MHXqVOzatQuHDh1CgwYNNNvlcjkAvHDlMblcDpVKhdzc3ArbPE8qlWpWP6vsKmhERKamSZMm+OSTT9CzZ0+DHletVuO3337DjRs3DHp
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"eroded = thresholded\n",
|
||
|
"for i in range(30):\n",
|
||
|
" eroded = ndimage.binary_erosion(eroded)\n",
|
||
|
"plt.imshow(eroded.astype(np.uint8), cmap='gray')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Now we will perform `dilation` 30 times in a row on our thresholded image. What does the dilation do?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.colorbar.Colorbar at 0x12794c9d0>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhkAAAGTCAYAAACF2QCoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACChklEQVR4nO3dd1xT1/8/8FcS9gaRpVRR6wQX7j1RWxxVKw5EW9wTcaJ1D0QtbqlW3AhYV92K1lG3IugHR90iCuKAIIIJkPv7w1/yNbIScm/m+/l45PGoyck95zYheeWcc8/hMQzDgBBCCCGEZXxNN4AQQggh+olCBiGEEEI4QSGDEEIIIZygkEEIIYQQTlDIIIQQQggnKGQQQgghhBMUMgghhBDCCQoZhBBCCOEEhQxCCCGEcIJCBiGEEEI4QSGDEEII0XMXLlxA9+7d4ebmBh6Ph4MHD5b6nPPnz8Pb2xtmZmaoUqUK/vjjD6XrpZBBCCGE6LlPnz6hXr16WLdunULlnz17hh9++AGtW7dGQkICZs6ciQkTJmDfvn1K1cujDdIIIYQQw8Hj8XDgwAH06tWr2DLTp0/HoUOHc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t8z1KMrIyAjNmjUr9CuZlEzdq3b6+fnh/fv3WLBgAVJTU+Hp6Yljx47J5gOlpqbKrZkxdOhQfPz4EevWrcPkyZNhZ2eHDh06ICwsTKl6We/JCA0NRePGjWFtbQ0nJyf06tUL//33n1wZhmEwb948uLm5wdzcHO3atcPdu3flyohEIowfPx6Ojo6wtLREjx49aNyPEKKTeDweevTooXLAkLK2tsb
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"dilated = thresholded\n",
|
||
|
"for i in range(30):\n",
|
||
|
" dilated = ndimage.binary_dilation(dilated)\n",
|
||
|
"plt.imshow(dilated.astype(np.uint8), cmap='gray')\n",
|
||
|
"plt.colorbar()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Now what about the combination of `erosion` with `dilation`?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhkAAAGTCAYAAACF2QCoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAB6dklEQVR4nO3dd1hT5/s/8HcChE0UqUAUFVe1Yh1YUbSOqlgtjtpWloBb6kTUItq6akWtqw5Q6xYQP21FbasoVuuo4kCw1TrrwAGiiEFmIJzfH/5OvoSZcbLI/bquXFd7csZzDEneuZ9znofHMAwDQgghhBCO8XXdAEIIIYTUTRQyCCGEEKIRFDIIIYQQohEUMgghhBCiERQyCCGEEKIRFDIIIYQQohEU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qakpcnJyMHHiRPzyyy+cDiNtZmaGNWvWYPLkyUrdrnr58mV4e3sjKyuLs7boI7FYrNB1Dqpgv5f++OMPWFtbq7yf/Px89OvXT6Nt5QrnlYzTp09jypQpSE5ORlJSEkpLS+Hl5YX8/HzZOitXrpQlpMuXL8PJyQkDBgzAmzdvZOuEhoYiISEB8fHxOHfuHPLy8uDt7Q2pVMp1kwkhRKcqBgwAqF+/PrZu3YrPPvuM04qGk5MT/P39lR4Po3nz5lrpxjEGuugu0RXO7y5JTEyU+/+dO3eiYcOGSElJQa9evcAwDNatW4f58+djxIgRAIDdu3fD0dERcXFxmDRpEsRiMbZv3469e/eif//+AICYmBi4uLjgxIkTGDhwINfNJoQQnRAIBFi4cCFmz54tCxgsNmgA4Kyi0bRpU9jY2Ci9XX5+PnJzc9U+PqEJ0jg
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ed = thresholded\n",
|
||
|
"for i in range(30):\n",
|
||
|
" ed = ndimage.binary_erosion(ed)\n",
|
||
|
"for i in range(30):\n",
|
||
|
" ed = ndimage.binary_dilation(ed)\n",
|
||
|
"plt.imshow(ed.astype(np.uint8), cmap='gray')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# End of detour - no more morphological operations\n",
|
||
|
"\n",
|
||
|
"Let's view our connected components labels a bit larger."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAyMAAAMeCAYAAAAON9u2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAC6rElEQVR4nOzde3wU5fn38c+yG3IwJBgOiRxqUGiBgiKgQaESNSBUVBQEq1HoIx6LiugjWLCuFgX8KVKl4qP011BTBRVBRKWAFhQVFBAFBYVKFKjhFCEE2JAN8/yxSSCQ0+7O7Ew23/frNS9ld+aeKyHAXHtf93W7DMMwEBERERERibBGdgcgIiIiIiINk5IRERERERGxhZIRERERERGxhZIRERERERGxhZIRERERERGxhZIRERERERGxhZIRERERERGxhZIRERERERGxhcfuAEREREREnMjn83H06FG7wzhF48aNiYuLszsMUygZERERERE5ic/no0V8PEV2B1KFtLQ0tm3bFhUJiZIREREREZGTHD16lCLgPiDW7mBOUAw8k5/P0aNHlYyIiIiIiESzWKD+P/I7l5IREREREZFqeHDWA7OTYjGDummJiIiIiIgtlIyIiIiIiIgtom2mR0RERETENDFlh1OU2h2AyTQzIiIiIiIitlAyIiIiIiIitlCZloiIiIhINdRNy1qaGREREREREVsoGREREREREVtE20yPiIiIiIhpPDirm5bf7gBMppkRERERERGxhZIRERERERGxhcq0RERERESqoW5a1tLMiIiIiIiI2ELJiIiIiIiI2CLaZnpEREREREwTg7ppWUkzIyIiIiIiYgslIyIiIiIiYguVaYmIiIiIVEPdtKylmREREREREbGFkhEREREREbFFtM30iIiIiIiYxoOzummV2B2AyTQzIiIiIiIitlAyIiIiIiIitlCZloiIiIhINdRNy1qaGREREREREVsoGREREREREVtE20yPiIiIiIhpYnBWNy0nxWIGzYyIiIiIiIgtlIyIiIiIiIgtVKYlIiIiIlINlWlZSzMjIiIiIiJiCyUjIiIiIiJiC5VpiYiIiIhUQ5seWkszIyIiIiIiYgslIyIiIiIiYotom+kRERERETGNB2d1sIq2h3fNjIiIiIiIiC2UjIiIiIiIiC2ibaZHRERERMQ06qZlLc2MiIiIiIiILZSMiIiIiIiILaJtpkdERERExDQxOKublpNiMYNmRkRERERExBZKRkRERERExBYq0xIRERERqYa6aVlLMyMiIiIiImILJSMiIiIiImKLaJvpERERERExjQdndbCKtod3zYyIiIiIiIgtlIyIiIiIiIgtom2mR0RERETENOqmZS3NjIiIiIiIiC2UjIiIiIiIiC2ibaZHRERERMQ0MTirm5aTYjGDZkZERERERMQWSkZERERERMQWKtMSEREREamGumlZSzMjIiIiIiJiCyUjIiIiIiJii2ib6RERERERMY0HZ3WwiraHd82MiIiIiIiILZSMiIiIiIiILZSMiIiIiIhUI8aBRzAmT57M+eefT5MmTWjZsiWDBw/m22+/rXSOYRh4vV5atWpFfHw8mZmZfP3117WOPW/ePDp37kxsbCydO3dm/vz5QUanZEREREREJGqtWLGCP/zhD6xatYqlS5fi9/vp378/hw4dqjjnySefZNq0acyYMYPPP/+ctLQ0+vXrx8GDB6sd99NPP2X48OHcdNNNfPnll9x0000MGzaM1atXBxWfyzAMI+SvTkREREQkChUWFpKcnMwmoIndwZzgINAJOHDgAElJSUFfv2fPHlq2bMmKFSu4+OKLMQyDVq1aMWbMGMaNGwdAcXExqampTJ06ldtvv73KcYYPH05hYSHvvfdexWsDBgzg9NNP59VXX61zPJoZERERERGphseBBwSSpROP4uLiOn09Bw4cACAlJQWAbdu2kZ+fT//+/SvOiY2NpW/fvnzyySfVjvPpp59Wugbg8ssvr/GaqigZERERERGpZ9q2bUtycnLFMXny5FqvMQyDsWPH0qdPH7p06QJAfn4+AKmpqZXOTU1NrXivKvn5+UFfU5Voa1UsIiIiIhL1tm/fXqlMKzY2ttZrRo8ezVdffcXKlStPec/lclX6tWEYp7xmxjUnUzIiIiIiIlINjxtignu+tpTHAEohKSkpqDUjd999NwsXLuTDDz+kTZs2Fa+npaUBgZmOM844o+L13bt3nzLzcaK0tLRTZkFqu6YqKtMSEREREYlShmEwevRo3nzzTT744APatWtX6f127dqRlpbG0qVLK147evQoK1as4KKLLqp23AsvvLDSNQBLliyp8ZqqaGZERERERCRK/eEPf+CVV17hrbfeokmTJhWzGcnJycTHx+NyuRgzZgxPPPEEHTp0oEOHDjzxxBMkJCRwww03VIxz880307p164q1Kffeey8XX3wxU6dO5eqrr+att95i2bJlVZaA1UTJiIiIiIhINTwe8DiwTKuuZs6cCUBmZmal1//+978zcuRIAB588EGOHDnCXXfdxc8//0xGRgZLliyhSZPjTY1//PFHGjU6XlR10UUXMWfOHCZOnMjDDz/M2Wefzdy5c8nIyAjq69E+IyIiIiIiJynfZ2R7LCQ5KBkpNKBtcej7jDiN1oyIiIiIiIgtVKYlIiIiIlKNGId104qJspomzYyIiIiIiIgtlIyIiIiIiIgtVKYlIiIiIlINR3bTiiKaGREREREREVsoGREREREREVuoTEtEREREpBoxbohx0Mf3McfsjsBcDvrWioiIiIhIQ6JkREREREREbKEyLRERERGR6rhx1sf3DursZQYnfWtFRERERKQBUTIiIiIiIiK2UJmWiIiIiEh1PDjr43t10xIREREREQmfkhEREREREbGFyrRERERERKqjMi1LOelbKyIiIiIiDYiSERERERERsYXKtEREREREqqMyLUs56VsrIiIiIiINiJIRERERERGxhcq0RERERESq0whw2x1E9NLMiIiIiIiI2ELJiIiIiIiI2EJlWiIiIiIi1fHgrDItl90BmEszIyIiIiIiYgslIyIiIiIiYguVaYmIiIiIVEdlWpbSzIiIiIiIiNhCyYiIiIiIiNhCZVoiIiIiItVx46wyrSijmREREREREbGFkhEREREREbGFyrRERERERKqjblqW0syIiIiIiIjYQsmIiIiIiIjYQmVaIiIiIiLVcaMnZgtpZkRERERERGyhZERERERERGyhSScRERERkeo4bdNDw+4AzKWZERERERERsYWSERERERERsYXKtEREREREquNBT8wW0syIiIiIiIjYQsmIiIiIiIjYQpNOIiIiIiLVUZmWpTQzIiIiIiIitlAyIiIiIiIittCkk4iIiIhIdVSmZSnNjIiIiIiIiC2UjIiIiIiIiC006SQiIiIiUp1GgNvuIE5wzO4AzKWZERERERERsYWSERERERERsYXKtEREREREquO0blqG3QGYSzMjIiIiIiJiCyUjIiIiIiJiCydNOomIiIiIOIvKtCylmREREREREbGFkhEREREREbGFkyadREREREScxY02PbSQZkZERERERMQWSkZERERERMQWKtMSEREREamOumlZSjMjIiIiIiJiCyUjIiIiIiJiCydNOomIiIiIOIsbZz0xq5uWiIiIiIhI+JSMiIiIiIiILZw06SQiIiIi4ixO2/TQSbGYQDMjIiIiIiJiCyUjIiIiIiJiC5VpiYiIiIhUx2mbHqqbloiIiIiISPiUjIiIiIiIiC2UjIiIiIiIVMfjwCNIH374IVdeeSWtWrXC5XKxYMGCSu+7XK4qj//5n/+pdsycnJwqr/H5fEHFpmRERERERCSKHTp0iHPPPZcZM2ZU+f5PP/1U6fjf//1fXC4XQ4YMqXHcpKSkU66Ni4sLKjYnLccRERERERGTDRw4kIEDB1b7flpaWqVfv/XWW1xyySWcddZZNY7rcrlOuTZYjp8Zef7552nXrh1xcXH06NGDjz76yO6QRERERKShsLskq5oyrcLCwkpHcXGxKV/url27eOedd7jllltqPbe
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x1000 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10, 10))\n",
|
||
|
"labels, num_labels = ndimage.label(thresholded)\n",
|
||
|
"plt.imshow(labels, cmap='jet')\n",
|
||
|
"plt.colorbar();"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"So, above are the labels for each connected component. Note that some individual coffee beans may be broken into two or more components and that sometimes multiple coffee beans may have been combined into one connected component."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Now we can calculate the \"center of mass\" of each connected component."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"coms = ndimage.center_of_mass(thresholded, labels, index=range(1,num_labels))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-1213340a2a7c110e",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Question Part B\n",
|
||
|
"\n",
|
||
|
"Change the parameters (and, if you like, change the processing steps) to label each coffee bean individually. Make a plot where each bean is marked with an \"x\".\n",
|
||
|
"\n",
|
||
|
"You may like to change:\n",
|
||
|
"\n",
|
||
|
" - the image channel used (red, green, blue, an average of all channels, ...)\n",
|
||
|
" - gaussian blur size\n",
|
||
|
" - threshold used for binarization\n",
|
||
|
" - optionally, any morphological image operations"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-9a32e77f790bb4da",
|
||
|
"locked": false,
|
||
|
"points": 2,
|
||
|
"schema_version": 3,
|
||
|
"solution": true
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAx4AAAMXCAYAAAC0NYP2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9fbhkVXkmjD91zqlT53TT3dowdNPSIvkFk0wwyodiwAhExKDGKBgwOkl0CHFelBkGHBM0GdDXgYiJmiGj12teB4xoMJmI4Gdso4IMUbHRKPgGURuBhB5mEgJ09/k+9fsDn9133fWstdfetXfVrnOe+7r2VVW79l57fe21nvv5WKvV7Xa74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yyy3yhje8Qb761a/Krl27ZHl5Wc4880zZv39/ds3VV18t7373u+VP/uRP5I477pDt27fLC1/4Qnn88cezay6++GK58cYb5YYbbpDbbrtN9u3bJy996UtlZWUlOS+t7jg7ijkcDofD4XA4HDXgscceky1btsh3vvMd2bRp06izk+Hxxx+XZzzjGfLoo4/K5s2bC9//v//3/5bDDz9cbrnlFnn+858v3W5XduzYIRdffLH8zu/8jog8Yd3Ytm2bvPOd75TXv/718uijj8q/+lf/Sj784Q/LeeedJyIi//iP/yg7d+6Uz3zmM/KiF70o6dlu8XA4HA6Hw+FwOMYMjz32WM+xsLCQdN+jjz4qIiJbt24VEZE9e/bI3r175cwzz8yu6XQ6cuqpp8rtt98uIiK7d++WpaWlnmt27Nghxx57bHZNCpx4OBwOh8PhcDgcAYzarSrkarVz507ZsmVLdlx
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x1000 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10, 10))\n",
|
||
|
"plt.imshow(im, cmap='gray')\n",
|
||
|
"plt.colorbar()\n",
|
||
|
"for com in coms:\n",
|
||
|
" ax.plot([com[1]],[com[0]], 'x') "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-5b9512404535239b",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Question Part C\n",
|
||
|
"\n",
|
||
|
"Describe what can go wrong when performing this connected components analysis to count and identify individual coffee beans. Name two possible problems and what do you see if each problem happens?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-b109315aba1b058b",
|
||
|
"locked": false,
|
||
|
"points": 2,
|
||
|
"schema_version": 3,
|
||
|
"solution": true
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"(Answer here.)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"celltoolbar": "Create Assignment",
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.11.10"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|