From 41eff16228fa715730764d9a1015ed0a2cae201d Mon Sep 17 00:00:00 2001 From: Lygerakis Fotios Date: Mon, 13 Mar 2023 18:57:32 +0100 Subject: [PATCH] Add files via upload --- assignment2_bonus_unsolved.ipynb | 143 +++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 assignment2_bonus_unsolved.ipynb diff --git a/assignment2_bonus_unsolved.ipynb b/assignment2_bonus_unsolved.ipynb new file mode 100644 index 0000000..33af499 --- /dev/null +++ b/assignment2_bonus_unsolved.ipynb @@ -0,0 +1,143 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "HoNMeHx5EDAm" + }, + "outputs": [], + "source": [ + "# By Univ.-Prof. Dr. Elmar Rueckert, 02.03.2022\n", + "# *******************************************************\n", + "\n", + "\n", + "import pickle, os\n", + "import numpy as np\n", + "from PIL import Image\n", + "from itertools import product" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Download the picture in this link https://cps.unileoben.ac.at/wp/DALLĀ·E-2023-02-09-17.32.48-robot-hand-communicating-with-sign-language.png and add it to the repository.\n", + "Name it 'hand.png'" + ], + "metadata": { + "id": "6SMr_2ZyFQJ0" + } + }, + { + "cell_type": "markdown", + "source": [ + "The \"filtered\" callback function takes a kernel (k) and an image as inputs, and applies the convolution operation on the image using the kernel. It first calculates the offset value for the kernel based on its shape, and then creates a zero-filled array of the same shape as the input image. It then iterates through all the pixel coordinates of the image, and for each pixel, it extracts the corresponding kernel-sized sub-image from the input image. It then performs the element-wise multiplication between the sub-image and the kernel, and sums up the resulting values to get a single output value. This output value is then clipped between 0 and 255, and stored in the corresponding pixel location of the output image. Finally, the filtered image is returned as output." + ], + "metadata": { + "id": "DZgexX8UE0HV" + } + }, + { + "cell_type": "code", + "source": [ + "\n", + "def filtered(k, image):\n", + " \n", + " return filtered_image" + ], + "metadata": { + "id": "pwuRm4gUE-eA" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Develop the image processing function that takes the filter and the callback as arguments" + ], + "metadata": { + "id": "zqrb5mT6EjRz" + } + }, + { + "cell_type": "code", + "source": [ + "def image_processing(k, callback):\n", + " # Acquire image\n", + "\n", + " # Display image" + ], + "metadata": { + "id": "wjdHq6ONEjau" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Main function" + ], + "metadata": { + "id": "h_yhIiCCEe_y" + } + }, + { + "cell_type": "code", + "source": [ + "if __name__ == '__main__':\n", + " # Laplace kernel\n", + " k_laplacian = np.asarray([[-1, -1, -1],\n", + " [-1, 8, -1],\n", + " [-1, -1, -1]])\n", + "\n", + " # Gaussian Smoothing Kernel\n", + " k_gaussian = np.asarray([[1, 1, 1],\n", + " [1, 1, 1],\n", + " [1, 1, 1]],dtype=float)\n", + " k_gaussian /= 9" + ], + "metadata": { + "id": "Y2-B4ii1EewG" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Image Processing" + ], + "metadata": { + "id": "XQdU2c8nEb5H" + } + }, + { + "cell_type": "code", + "source": [ + " image_processing(k_laplacian,filtered)\n", + " image_processing(k_gaussian, filtered)" + ], + "metadata": { + "id": "1XN9C4p-EZTF" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file