computer-vision/edge-detection.ipynb

172 lines
311 KiB
Plaintext
Raw Normal View History

2019-12-08 03:13:45 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2><center>edge detection</center></h2>"
]
},
{
"cell_type": "code",
"execution_count": 3,
2019-12-08 03:13:45 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f6a9f8a01d0>"
2019-12-08 03:13:45 +00:00
]
},
"execution_count": 3,
2019-12-08 03:13:45 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAW8AAAD8CAYAAAC4uSVNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nOy9v8t125bn9RljzLWfc++tyixF2gYNBFMTDYwFwaDRSA0MBCvqQDARI6FTf2AkXNFAEE00kobGv0BaTfzRKI0gtjRio9Ba977PXnOMYfAdcz/vuXXOqbKqD30u9cxL1Tnnffdee6255hw/vuM7vtO6m8/xOT7H5/gcv13D/27fwOf4HJ/jc3yO///j03h/js/xOT7Hb+H4NN6f43N8js/xWzg+jffn+Byf43P8Fo5P4/05Psfn+By/hePTeH+Oz/E5Psdv4fjRjLeZ/VNm9j+Z2V83s3/tx/qdz/E5Psfn+LM47MfgeZtZAP8z8E8CfwP4q8A/393/49/xH/scn+NzfI4/g+PHirz/MeCvd/f/0t1P4D8F/sKP9Fuf43N8js/xZ26sH+m6fw743776778B/OPf9+Fvvln9u7/7RhsYgBk2CUHTfCQHNn+vv/l6KIOw19/pk/MZm++9/qRp0G+YQeu/+ToLMfv4V+zbn9O355rnNz++3/P7/a17NF2yP+7n/Obc+bc+76/f//hnd3/rcx+f/7jex5P+xviYGs3pa+K++olv/ZrNd+yreftqjux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R1hsWVPVWiTKrtgk3sFdtyIvAJbSYLv0dKHfXy4IY1dNJuFQhtl
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import cv2\n",
"import math\n",
"import numpy as np\n",
"from scipy.signal import convolve2d\n",
"from matplotlib import pyplot as plt\n",
"\n",
"img = cv2.imread('sheep.png')\n",
"plt.imshow(img[:,:,::-1])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"sobel filter"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f6a9c204bd0>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAACTCAYAAAB1YlneAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nOy9Way2S3bf9VtV9TzvsKdvOkOf06cnu9ttG3CcWFEwRiIJAQshBZAIhguChOQrhISElCDEDTfkmjsMQkKRQogUQiIyB3BwiAw2tuN4iB139zndfcZv3nu/0/PUwEXVqqp3f9/p7sRpcmztko7Ot/d+32eoWrWG//qvVZJS4nbcjttxO27H765h/mk/wO24HbfjdtyOf/LjVrnfjttxO27H78Jxq9xvx+24Hbfjd+G4Ve6343bcjtvxu3DcKvfbcTtux+34XThulfvtuB2343b8LhzfNeUuIj8uIr8hIr8lIn/yu3Wf23E7bsftuB0vDvlu8NxFxAK/CfwR4JvAzwH/bkrp1/6J3+x23I7bcTtuxwvju+W5/37gt1JKX00pTcCfBf7od+let+N23I7bcTtujO+Wcn8T+Eb38zfL727H7bgdt+N2/P8w3D+tG4vITwI/CSDj+PsW914lrmL52/FnU2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gu72mdJlHtscelCamioIchZOy0hLsiKTv4RbCNKcIo7XtVqVhaREC/UemiIn02hXtSjcaMJHCxvrMxMecUynP68s41SZo6JkNq85y6d+uhnwwvNMOW6qZskVkPl+kEW2lrceR5lo0XRJ2AVLHw7FR0a5dyYl9cRIZOSUcheiG
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"kx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) / 4\n",
"ky = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) / 4\n",
"\n",
"grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) / 256\n",
"\n",
"blur = convolve2d(grey, np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) / 9)\n",
"\n",
"dx = convolve2d(blur, kx)\n",
"dy = convolve2d(blur, ky)\n",
"\n",
"x = np.concatenate((dx, dy), axis=1)\n",
"\n",
"plt.imshow(x)"
]
},
2019-12-08 03:13:45 +00:00
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f758913b8d0>"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAACSCAYAAAC+Pop7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAfTUlEQVR4nO2dfexmRXXHv8dFpNJGXqRkBSyoGw1Ny0o3iClpfKmKtBabGANpIjUk+w8m2jSx0CZ9S0xom9ZqtMRtpWLSolRrIYaIFG3sH6246AoIIluFsMvL8qLW1MRWPP3juReG4ZyZM/fOfX3OJ/nl9zxz7505c5+53zlz5vx+DzEzHMdxnHXxnKk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ZEczdLTYugVLyCZ1rjV3XEtbjNuQyiUbpM1X7VjpymJOwr707JKU/S7oTi16b6jy5qucir/OiZn3MfMeZt5z0ok7+prxDCSvVYtnhkKsZdOkls2SB2YNZUgbvbl+afWEMfI4pz2uuz0mxd9TbYwhPFbBtk6gS2apk5czD7qK+yNtuKX5faQpPwzgtOC8U5uy0Uh566kwTlxHanPLEg6yCk8oqrlJxbrBG9cdlmuTkcXGMSjZC1gi7rU7Y9FV3G8AcEnz+hIA1wfl72iyZs4F8P0gfDM4pUKslUuphFL2iPUBLc1+SXmlsXeea8tiY2pC7CPsQ00Kqf7PFcnRKNlcXypDfkZLGwNjk/2vkER0LYDXAHghER0C8EcArgRwHRFdCuB+AG9vTr8RwAUADgL4IYB3DmBzljjsIB1PXachCbAlPFD6kKb2CeKMmBJh1rx
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"kx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) / 4\n",
"ky = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) / 4\n",
"\n",
"grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) / 256\n",
"\n",
"blur = convolve2d(grey, np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) / 9)\n",
"\n",
"dx_grey = convolve2d(grey, kx)\n",
"dy_grey = convolve2d(grey, ky)\n",
"\n",
"dx_blur = convolve2d(blur, kx)\n",
"dy_blur = convolve2d(blur, ky)\n",
"\n",
"dx = np.concatenate((dx_grey, dx_blur[1:-1, 1:-1]), axis=1)\n",
"dy = np.concatenate((dy_grey, dy_blur[1:-1, 1:-1]), axis=1)\n",
"\n",
"x = np.sqrt(pow(dx, 2) + pow(dy, 2))\n",
"plt.imshow(x>0.08)"
]
}
],
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}