{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "6eIeDemCSbdp" }, "source": [ "## $\\large{Quiz}$" ] }, { "cell_type": "markdown", "metadata": { "id": "aPzuwxR5Sbd3" }, "source": [ "請使用 Laplacian Filter 將跑車的輪廓找出來
\n", "\n", " \n", "\n", "Laplacian Filter (5x5):\n", "$\\begin{bmatrix}\n", "0 & 0 &-1 & 0 & 0 \\\\\n", "0 & -1 & -2 & -1 & 0\\\\\n", "-1 & -2 & 16 & -2 & -1\\\\\n", "0 & -1 & -2 & -1 & 0\\\\\n", "0 & 0 &-1 & 0 & 0\n", "\\end{bmatrix}$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "rZ65aUaxN4Mg" }, "outputs": [], "source": [ "# upload Data\n", "!wget -q https://github.com/TA-aiacademy/course_3.0/releases/download/CVCNN_Data/CVCNN_part1.zip\n", "!unzip -q CVCNN_part1.zip" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "fydrLdmJSbd7" }, "outputs": [], "source": [ "path = \"car.png\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "jssGweacVGXj" }, "outputs": [], "source": [ "import cv2\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "zHYkvh9VSbeC" }, "outputs": [], "source": [ "def load_img(path):\n", " img = cv2.imread(path)[:,:,::-1]\n", " laplacian_filter = np.array([[0, 0, -1, 0, 0],\n", " [0, -1, -2, -1, 0],\n", " [-1, -2, 16, -2, -1],\n", " [0, -1, -2, -1, 0],\n", " [0, 0, -1, 0, 0]])\n", " edge = cv2.filter2D(img, -1, laplacian_filter)\n", " return edge" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "O4TewCfxSbeG" }, "outputs": [], "source": [ "import cv2\n", "import numpy as np\n", "quiz_img = cv2.imread(\"car_ans.png\")[:,:,::-1]\n", "assert np.array_equiv(load_img(path), quiz_img)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Hnsf3QKrVlQj" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "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.7.12" } }, "nbformat": 4, "nbformat_minor": 4 }