Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-91: Added Jupyter file, input and output images and readme for hole detection #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions Hole_Detection/Hole_Detection.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Importing Libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Reading Input Images"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"img1 = cv2.imread(\"C:\\\\Users\\\\Srimonti\\\\Documents\\GSSoC21\\\\Hole_Detection\\\\sample1.jpg\",1);\n",
"img2 = cv2.imread(\"C:\\\\Users\\\\Srimonti\\\\Documents\\GSSoC21\\\\Hole_Detection\\\\sample2.jpg\",1);\n",
"img3 = cv2.imread(\"C:\\\\Users\\\\Srimonti\\\\Documents\\GSSoC21\\\\Hole_Detection\\\\sample3.jpg\",1);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Converting Input Images to Grayscale"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"grey1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)\n",
"grey2 = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)\n",
"grey3 = cv2.cvtColor(img3,cv2.COLOR_BGR2GRAY)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Performing Gaussian Blurring"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"gauss1 = cv2.GaussianBlur(img1,(5,5),200)\n",
"gauss2 = cv2.GaussianBlur(img2,(5,5),200)\n",
"gauss3 = cv2.GaussianBlur(img3,(5,5),200)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Threshold Detection"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"ret,thresh1 = cv2.threshold(gauss1,127,255,0)\n",
"ret,thresh2 = cv2.threshold(gauss2,127,255,0)\n",
"ret,thresh3 = cv2.threshold(gauss3,127,255,0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Performing Blob Detection"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"detector = cv2.SimpleBlobDetector_create()\n",
"keypoint1 = detector.detect(thresh1);\n",
"imgkeypoint1 = cv2.drawKeypoints(thresh1,keypoint1,np.array([]),(0,255,0),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)\n",
"keypoint2 = detector.detect(thresh2);\n",
"imgkeypoint2= cv2.drawKeypoints(thresh2,keypoint2,np.array([]),(0,255,0),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)\n",
"keypoint3 = detector.detect(thresh3);\n",
"imgkeypoint3 = cv2.drawKeypoints(thresh3,keypoint3,np.array([]),(0,255,0),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Output Image Display"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-1"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cv2.imshow(\"legend\",imgkeypoint1);\n",
"cv2.waitKey(0)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cv2.imshow(\"legend\",imgkeypoint2);\n",
"cv2.waitKey(0)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-1"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cv2.imshow(\"legend\",imgkeypoint3);\n",
"cv2.waitKey(0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.6rc1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Binary file added Hole_Detection/Input Images/sample1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hole_Detection/Input Images/sample2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hole_Detection/Input Images/sample3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hole_Detection/Output Images/sample1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hole_Detection/Output Images/sample2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hole_Detection/Output Images/sample3.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Hole_Detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Libraries Used

#### imread()
cv2.imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix.

#### cvtColor()
cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV.

#### GaussianBlur()
In the Gaussian Blur operation, the image is convolved with a Gaussian filter instead of the box filter. The Gaussian filter is a low-pass filter that removes the high-frequency components are reduced. It also smoothens or blurs the image. You can perform this operation on an image using the Gaussianblur() method of the imgproc class. Gaussian blurring is highly effective in removing Gaussian noise from an image.

#### cv2.threshold()
If pixel value is greater than a threshold value, it is assigned one value (may be white), else it is assigned another value (may be black). The function used is cv2.threshold. First argument is the source image, which should be a grayscale image. Second argument is the threshold value which is used to classify the pixel values. Third argument is the maxVal which represents the value to be given if pixel value is more than (sometimes less than) the threshold value.

#### cv2.SimpleBlobDetector_create()
SimpleBlobDetector is an algorithm which is controlled by parameters in the following way-

Thresholding : Convert the source images to several binary images by thresholding the source image with thresholds starting at minThreshold. These thresholds are incremented by thresholdStep until maxThreshold. So the first threshold is minThreshold, the second is minThreshold + thresholdStep, the third is minThreshold + 2 x thresholdStep, and so on.
Grouping : In each binary image, connected white pixels are grouped together. Let’s call these binary blobs.
Merging : The centers of the binary blobs in the binary images are computed, and blobs located closer than minDistBetweenBlobs are merged.
Center & Radius Calculation : The centers and radii of the new merged blobs are computed and returned.