"We know to use a library in python the first thing we have to do is importing the package.\n",

"We know how to use a library in python the first thing we have to do is importing the package.\n",

"\n",

"It is conventional to import `OpenCV2` with the alias `cv`, obviously it is not required."

]

...

...

@@ -141,9 +141,9 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"`imread` returns a [`Numpy`](https://numpy.org/) [`ndarray`](https://numpy.org/doc/stable/reference/arrays.ndarray.html).\n",

"`imread` returns a [`NumPy`](https://numpy.org/) [`ndarray`](https://numpy.org/doc/stable/reference/arrays.ndarray.html).\n",

"\n",

"[`Numpy`](https://numpy.org/) is a library which is part of [`SciPy`](https://www.scipy.org/) project, with the aim to provide a smart and powerful system to work with multidimensional matrices."

"[`NumPy`](https://numpy.org/) is a library which is part of [`SciPy`](https://www.scipy.org/) project, with the aim of providing a smart and powerful system to work with multidimensional matrices."

]

},

{

...

...

@@ -161,7 +161,7 @@

"source": [

"`ndim` method of NumPy array returns the number of matrix dimensions. \n",

"\n",

"Our matrix has `3` dimensions, this makes sense: Two dimensions are the height and the width of the image, the third is represented by color's channels of each pixel."

"Our matrix has `3` dimensions, this makes sense: two dimensions are the height and the width of the image, the third is represented by color's channels of each pixel."

]

},

{

...

...

@@ -239,7 +239,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"Now, we have the basis to understand what we see above, but it is not very useful to understand \"how we are seeing\".\n",

"Now, we have the basis to understand what we see above, but it is not very helpful to understand \"what\" we are seeing.\n",

"\n",

"Let's try to visualize the image in a more useful way."

]

...

...

@@ -280,7 +280,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"(Un)luckily we are using a Jupyter notebook, and the windows shown is not convinient.\n",

"(Un)luckily we are using a Jupyter notebook, and the window shown is not convenient.\n",

"\n",

"To solve it we can use the library [`matplotlib`](https://matplotlib.org/) of the project [`SciPy`](https://www.scipy.org/)."

]

...

...

@@ -306,7 +306,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"How we see the result is the same, but there is a small difference.\n",

"As we see the result is the same, but there is a small difference.\n",

"\n",

"In the code we spot [`cv.cvtColor`](https://docs.opencv.org/4.3.0/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab). It converts the image from an encoding to another one.\n",

"\n",

...

...

@@ -358,7 +358,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"Obviously, we can also save an image before we have done some edits."

"Obviously, we can also save an image after we have done some edits."

]

},

{

...

...

@@ -388,8 +388,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"It is useful to understand what is a color model, and how works that we are currently using.\n",

"\n"

"It is useful to understand what is a color model, and how the one we are currently using works."

"This is a 3D graph of the **RGB** model. Each axes corresponding to a number, so we need three number to identify a single color."

"This is a 3D graph of the **RGB** model. Each axes corresponding to a number, so we need three values to identify a single color."

]

},

{

...

...

@@ -477,9 +476,9 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"We can see how the range of components is very wide, although we are just taking about yellow.\n",

"We can see how the range of components is very wide, although we are just talking about yellow.\n",

"\n",

"let's not worry about that and try to use this information to find the yellow element in the original image."

"Let's not worry about that and try to use this information to find the yellow element in the original image."

]

},

{

...

...

@@ -505,7 +504,7 @@

"Not the best of the results.\n",

"\n",

"But what have we done?\n",

"We defined two color boundaries based on the range discovered above, and with function `cv.inRange` we generated a mask of the pixels which are in that range."

"We defined two color boundaries based on the range discovered above, and with the function `cv.inRange` we generated a mask of the pixels which are in that range."

]

},

{

...

...

@@ -593,7 +592,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

"With easy systems of color matching is preferred to use **HSL** or **HSV** rather than **RGB**.\n",

"With easy systems of color matching it is preferred to use **HSL** or **HSV** rather than **RGB**.\n",

"\n",

"*n.b. between **HSL**, **HSV** and **RGB** there is a one-to-one correspondence, so there is not information loss in conversion*"

]

...

...

@@ -611,14 +610,14 @@

"source": [

"As in all measure systems it is a smart idea to remove the noise as soon as possible, when our system contains as much information as possible\\*.\n",

"\n",

"(\\*)*talk to your trusted electronic engineer*"

"(\\*)*talk to your trusted electronic engineer*"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"In our case this suggests us that we should have removed the reasons of the small blob before applying the `cv.inRange` function, with which we lost most of image's informations.\n",

"In our case this suggests us that we should have removed the reasons of the small blob before applying the `cv.inRange` function, with which we lost most of the image's information.\n",

"\n",

"But, maybe this time we can correct it even with considerable information loss."

]

...

...

@@ -645,7 +644,7 @@

"source": [

"The function `cv.findContours` takes into account a bitmap and returns a list of blob's contours.\n",

"\n",

"`cv.drawContours` draws a list of contours on a image. The second argument is the list of contours, the third one is the position in array of the contours we want to draw (`-1` means \"all\"), the fourth one is the \"color\" of contour and the last one is the size of the contour (`-1` means \"fill the contour\")."

"`cv.drawContours` draws a list of contours on an image. The second argument is the list of contours, the third one is the position in array of the contours we want to draw (`-1` means \"all\"), the fourth one is the \"color\" of contour and the last one is the size of the contour (`-1` means \"fill the contour\")."

]

},

{

...

...

@@ -668,7 +667,7 @@

"cell_type": "markdown",

"metadata": {},

"source": [

" With a simple filter on contours' list we have separated valid blobs from false positive"

" With a simple filter on contours' list we have separated valid blobs from false positives."

]

},

{

...

...

@@ -788,7 +787,7 @@

"\n",

"Before going on, let's understand what we have done.\n",

"\n",

"with `.copy()` method on `NumPy` array we created a copy of it.\n",

"With `.copy()` method on `NumPy` array we created a copy of it.\n",

"\n",

"The circles list is provided in float format, but the image pixels are identified by integer coordinates, so before we apply a rounding of the matrix `np.around` we convert it to an integer notation `np.uint16`.\n",

"\n",

...

...

@@ -801,7 +800,7 @@

"source": [

"Let's try to get a better result.\n",

"\n",

"As we have already said before, to do any operation on an image is a smart idea to filter as much noise as possible."

"As we have already said before, to do any operation on an image it is a smart idea to filter as much noise as possible."

]

},

{

...

...

@@ -822,9 +821,9 @@

"source": [

"The median blur filter is a great filter to remove noise from an image.\n",

"\n",

"The function [`cv.medianBlur`](https://docs.opencv.org/4.3.0/d4/d86/group__imgproc__filter.html#ga564869aa33e58769b4469101aac458f9) requires the dimension of the kernel will be used to create the blur effect.\n",

"The function [`cv.medianBlur`](https://docs.opencv.org/4.3.0/d4/d86/group__imgproc__filter.html#ga564869aa33e58769b4469101aac458f9) requires the dimension of the kernel which will be used to create the blur effect.\n",

"\n",

"For simple folk, the bigger the kernel size the more the losses of image's information."

"For dummies, the bigger the kernel size the more the losses of the image's information."