{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "**Name:**\n",
        "\n",
        "**Date:**\n",
        "\n",
        "**Description of activity:**\n"
      ],
      "metadata": {
        "id": "sczaGya92i48"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Mount Google Drive\n"
      ],
      "metadata": {
        "id": "mv3Oarmb2zRK"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "1i3bvglG2d8z",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "8b342a22-6dc1-4aae-98b2-3c1b4c2bac4f"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Mounted at /drive\n"
          ]
        }
      ],
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/drive')"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Import Libraries"
      ],
      "metadata": {
        "id": "GXNipdi-3F1Z"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from PIL import Image, ImageFilter\n",
        "from matplotlib import pyplot as plt"
      ],
      "metadata": {
        "id": "8Nmg8IhE3KfV"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Exercises\n",
        "\n",
        "In this activity you will explore and experiment with  several functions from the Image module of the Python Imaging Library (PIL).  Wikipedia has some [background information on PIL](https://en.wikipedia.org/wiki/Python_Imaging_Library) if you're interested in reading more about this library.  Some of the functions to be explored are similar to functions you have written while others will be new.  \n"
      ],
      "metadata": {
        "id": "MJ8VoPpTy-mD"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Image.convert**\n",
        "\n",
        "The [convert function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.convert) can be used to convert an image to black and white or grayscale format.  To convert an image to black and white, the user would pass a '1' as the parameter for this function.  This 1 indicates it should be converted to 1-bit pixels.  (With 1 bit of storage, you can have either a 1, for white, or a 0, for black.). To convert the image to grayscale, the user would pass an 'L' as the parameter.  This 'L' indicates it should be converted to 8-bit pixels.  Look at the documentation (link above) to learn how it converts an image to grayscale.  Then **answer the following questions** and **test this function** below.\n",
        "\n",
        "\n",
        "\n",
        "1.   Explain the difference between black and white images and grayscale images.\n",
        "\n",
        "\n",
        "2.   Explain how this grayscale function is different from the grayscale function that you defined in a previous activity.\n",
        "\n",
        " "
      ],
      "metadata": {
        "id": "lyQoZbAeYM2q"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test the convert function here\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "4cewcCckBk6N"
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Image.crop**\n",
        "\n",
        "Explore the [crop function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.crop). \n",
        "\n",
        "Answer the following questions about this function: \n",
        "What parameters are needed.  (How) Is this \n",
        "\n",
        "1.   What parameters are needed when using this function?  What happens if no parameters are provided?\n",
        "\n",
        "2.   What similarities and differences do you see between this <code>crop</code> function and the <code>crop</code> function that you defined in a previous activity?\n",
        "\n"
      ],
      "metadata": {
        "id": "S6Mg9BgzAdC6"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test the crop function here\n"
      ],
      "metadata": {
        "id": "CbazLNCZB7bn"
      },
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Image.paste**\n",
        "\n",
        "Read the documentation for the [paste function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.paste).  **Test it** with several different parameters, similar to how we tested the <code>copyInto</code> function, and then **answer the following questions**:\n",
        "\n",
        "\n",
        "1.   How is the <code>paste</code> function similar to the <code>copyInto</code> function that you wrote?\n",
        "\n",
        "2.   How is it different?\n",
        "\n",
        "3.  What happens if you provide only the image to be pasted as a parameter?\n",
        "\n"
      ],
      "metadata": {
        "id": "KQU2gGA9eEra"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test the paste function here\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "EYN2IJBlFcU2"
      },
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Resizing**\n",
        "\n",
        "The Image module has several ways to resize an image.  The [reduce function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.reduce) reduces the size of an image by a specified factor, or reduces a specified region of the image by the specified factor.  This would be similar to cropping and then reducing the size.\n",
        "\n",
        "The [resize function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) will change the size of the image to the specified pixel size.  Alternatively, it will change a portion of the image to a specified pixel size.  The image may be resized to be smaller or larger.\n",
        "\n",
        "**Test** these functions below with several different images and parameters.  Then **answer the following questions**:\n",
        "\n",
        "\n",
        "\n",
        "1.   How would you use the <code>reduce</code> function so that it works like the <code>quarter</code> function that we defined?\n",
        "2.   How would you use the <code>resize</code> function so that it works like the <code>quarter</code> function?\n",
        "3.  Which function would you use to get a resulting image similar to the <code>quadruple</code> function that we defined, and how would you use it?\n",
        "\n"
      ],
      "metadata": {
        "id": "QyiwTILpgu-o"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test reduce and resize functions here\n"
      ],
      "metadata": {
        "id": "CIzv0YYYgNcQ"
      },
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Image.Rotate**\n",
        "\n",
        "Explore the [rotate function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.rotate).  **Test** it below with several different angles of rotation then **answer the following questions**:\n",
        "\n",
        "\n",
        "1.   Explain how this <code>rotate</code> function is similar to the <code>rotate</code> we defined in a previous activity.\n",
        "\n",
        "2.   What additional capabilities does this function provide that our <code>rotate</code> function did not have?\n",
        "\n"
      ],
      "metadata": {
        "id": "H4BhAXnki0Hy"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test the rotate function here\n",
        "\n"
      ],
      "metadata": {
        "id": "eY8RhzjXi3jw"
      },
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "**(OPTIONAL if time permits) Blurring**\n",
        "\n",
        "Blurring an image can be done through the use of the [filter function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.filter).  The ImageFilter module contains definitions for pre-defined set of filters. Explore how the BLUR and [BoxBlur](https://pillow.readthedocs.io/en/stable/reference/ImageFilter.html#PIL.ImageFilter.BoxBlur) filters work and then test them below. \n",
        "\n",
        "**Challenge Question:** If you wanted to blur only a section of an image, would you use a combination of functions such as <code>crop</code>, <code>blur</code>, and <code>paste</code>, or would you write your own function?  Explain.\n",
        "\n"
      ],
      "metadata": {
        "id": "j_BFc8bYMfrO"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test the filter function here\n",
        "\n"
      ],
      "metadata": {
        "id": "tyUHkcihZwyR"
      },
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "**(OPTIONAL if time permits) New effects**\n",
        "\n",
        "**Image.getchannel**\n",
        "\n",
        "The [getchannel function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getchannel)  returns a grayscale image based on either the red, green, or blue values (*i.e.*, channels 0, 1, or 2).  **Test** it below and see if you can observe any differences between the results from different channels.\n",
        "\n",
        "**Explain the difference(s) here:**   \n",
        "\n",
        "\n",
        "\n",
        "**Image.blend**\n",
        "\n",
        "The [blend function](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.blend) takes two images (of the same size) as parameters and creates a new image which is an overlay of one image on top of the other.  The user may also specify a value which indicates the percentage of the color values to be used in the first image.  For example, if you would like to see more of the first image showing through the blend and less of the second image, you might call the function like:<br><code>newImage = Image.blend(image1, image2, 0.65)</code>.\n",
        "<br>This would use 65% of the pixel color values from image1 and 35% of the color values from image2.  In the Code cell below, experiment with blending two images and using different percentages of each image.\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "-3t5fMuKHuqE"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Test getchannel and blend functions here\n"
      ],
      "metadata": {
        "id": "8WMLzD5bAQxP"
      },
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Saving and Submitting\n",
        "\n",
        "Once you have created results that you are pleased with, skim through your notebook and make sure everything looks the way you expect.  Make sure that your Code cells have been run and that your results for the color change effects are showing.  If it all looks good, save this notebook as a pdf.  (Go to File -> Print -> Save as PDF)\n",
        "\n",
        "Submit your PDF file on Kit."
      ],
      "metadata": {
        "id": "m8jTI0_OBDRM"
      }
    }
  ]
}