{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "PXmQmDurBXv0" }, "source": [ "## $\\large{Quiz}$" ] }, { "cell_type": "markdown", "metadata": { "id": "nRlD1qLRBXv9" }, "source": [ "請將左圖中的龍貓完成底下這幾個影像處理,以得到右圖
\n", "1. 以一半影像長、寬減 1 的 index 作為中心點,將旋轉 45 度角\n", "2. 使用鏡像反射補值法\n", "3. 將影像放大 2 倍\n", "\n", "![](https://hackmd.io/_uploads/rkOHU2DG6.png)\n" ] }, { "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": "YqpUdo7tBXwA" }, "outputs": [], "source": [ "path = \"totoro.png\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Bu7tyjsZEKuv" }, "outputs": [], "source": [ "import cv2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Pt8RwnfWEQjb" }, "outputs": [], "source": [ "def load_img(path):\n", " img = cv2.imread(path)[:,:,::-1]\n", " h, w, _ = img.shape\n", " center = (w//2-1, h//2-1)\n", " M = cv2.getRotationMatrix2D(center, 45, 1)\n", " rotate_img = cv2.warpAffine(img, M, (w*2, h*2), borderMode=cv2.BORDER_REFLECT)\n", " return rotate_img" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "S-GyAo2RGJve" }, "outputs": [], "source": [ "import cv2\n", "import numpy as np\n", "quiz_img = cv2.imread(\"totoro_ans.png\")[:,:,::-1]\n", "assert np.array_equiv(load_img(path), quiz_img)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "LOF8kIhkFSj3" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [], "include_colab_link": true }, "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": 0 }