{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "8b774e19-8bed-4711-ba17-e22584f09ec6"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "from PIL import Image, ImageFilter\n",
        "import random\n",
        "import cv2\n",
        "import os, glob\n",
        "\n",
        "#t = pd.read_csv('../input/train_info.csv'); t.head()\n",
        "#s = pd.read_csv('../input/submission_info.csv'); s.head()\n",
        "train_files = [f for f in glob.glob(\"../input/train_2/*\")]\n",
        "i_ = 0\n",
        "plt.rcParams['figure.figsize'] = (10.0, 10.0)\n",
        "plt.subplots_adjust(wspace=0, hspace=0)\n",
        "for l in train_files[:100]:\n",
        "    im = cv2.imread(l)\n",
        "    im = cv2.resize(im, (50, 50)) \n",
        "    plt.subplot(10, 10, i_+1) #.set_title(l)\n",
        "    plt.imshow(cv2.cvtColor(im, cv2.COLOR_BGR2RGB)); plt.axis('off')\n",
        "    i_ += 1"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "33d41a5d-8f66-4358-aba2-04e77e2a5989"
      },
      "source": [
        "## Artwork from Artwork - Is that Possible?"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "46d79554-023b-451c-abc8-37d68fc4ca3e"
      },
      "outputs": [],
      "source": [
        "im1 = Image.open('../input/train_2/23504.jpg')\n",
        "im2 = Image.open('../input/train_2/22873.jpg')\n",
        "w1, h1 = im1.size; w2, h2 = im2.size\n",
        "p2 = im2.load() #get pixels\n",
        "for x in range(0, w1,2):\n",
        "    if x < w2:\n",
        "        for y in range(0, h1,2):\n",
        "            if y < h2:\n",
        "                 im1.putpixel((x, y), p2[x,y])\n",
        "plt.imshow(im1); plt.axis('off')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "7a2cecd1-aaf7-4b31-85df-851a4a39dc14"
      },
      "source": [
        "## Lets test some basic filters\n",
        "\n",
        "    BLUR\n",
        "    CONTOUR\n",
        "    DETAIL\n",
        "    EDGE_ENHANCE\n",
        "    EDGE_ENHANCE_MORE\n",
        "    EMBOSS\n",
        "    FIND_EDGES\n",
        "    SMOOTH\n",
        "    SMOOTH_MORE\n",
        "    SHARPEN"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "b543ad5f-c8f3-4905-aee9-c52662db74a4"
      },
      "outputs": [],
      "source": [
        "iFilters = [ImageFilter.BLUR, ImageFilter.CONTOUR, ImageFilter.DETAIL, \n",
        "            ImageFilter.EDGE_ENHANCE, ImageFilter.EDGE_ENHANCE_MORE, ImageFilter.EMBOSS, \n",
        "            ImageFilter.FIND_EDGES, ImageFilter.SMOOTH, ImageFilter.SMOOTH_MORE, \n",
        "            ImageFilter.SHARPEN]\n",
        "plt.rcParams['figure.figsize'] = (6.0, 20.0)\n",
        "plt.subplots_adjust(wspace=0, hspace=0)\n",
        "for i in range(10):\n",
        "    im3 = im2\n",
        "    im3 = im3.filter(iFilters[i])\n",
        "    #im = cv2.resize(im, (300, 300)) \n",
        "    plt.subplot(5, 2, i+1) #.set_title(l)\n",
        "    plt.imshow(im3); plt.axis('off')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "3d62bcc6-2992-455a-80b5-3b6964aca751"
      },
      "source": [
        "## Lets add a third image"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "37155faa-ebba-4cad-925e-c6c4c269b5de"
      },
      "outputs": [],
      "source": [
        "plt.rcParams['figure.figsize'] = (10.0, 10.0)\n",
        "im2 = Image.open(train_files[61])\n",
        "im2 = im2.resize((w1,h1), Image.ANTIALIAS)\n",
        "w2, h2 = im2.size\n",
        "p1 = im1.load(); p2 = im2.load()\n",
        "for x in range(0, w1,1):\n",
        "    if x < w2:\n",
        "        for y in range(0, h1,1):\n",
        "            if y < h2:\n",
        "                 im1.putpixel((x, y), (p1[x,y][0], p1[x,y][1], p2[x,y][2]))\n",
        "plt.imshow(im1); plt.axis('off')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "7df55d02-c198-47e8-84e0-aa9c7b274b9e"
      },
      "source": [
        "## Features, Features, Features"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "d1ad76df-d866-463f-b177-11d78caa5878"
      },
      "outputs": [],
      "source": [
        "from PIL import ImageStat\n",
        "stats = ImageStat.Stat(im1, mask=None)\n",
        "print(stats.extrema)\n",
        "print(stats.count)\n",
        "print(stats.sum)\n",
        "print(stats.sum2)\n",
        "print(stats.mean)\n",
        "print(stats.median)\n",
        "print(stats.rms)\n",
        "print(stats.var)\n",
        "print(stats.stddev)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "bcc95910-8b81-450c-9c34-1162c0b2ffef"
      },
      "outputs": [],
      "source": [
        ""
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "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.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}