{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This tool mix together two pictures taking their edges."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image, ImageChops, ImageFilter\n",
    "from urllib.request import urlopen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic1 = Image.open(r'2.png') #Pic from a file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic1 = Image.open(urlopen('https://d7hftxdivxxvm.cloudfront.net/?resize_to=fit&width=480&height=640&quality=80&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FoMDDSm77JFzMIYbi81xOaw%2Flarge.jpg')) #Pic from an url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic2 = Image.open(r'2.png') #Pic from a file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic2 = Image.open(urlopen('https://publicdelivery.b-cdn.net/wp-content/uploads/2020/01/Thomas-Ruff-Portrait-E.-Zapp-1990-scaled.jpg')) #Pic from an url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "pic1 = pic1.convert(\"L\").filter(ImageFilter.FIND_EDGES).filter(ImageFilter.Kernel((3, 3), (1, -3, -1, -1, 8, -1, 8, -1, -1), 1, 2)) #Create edges\n",
    "pic2 = pic2.convert(\"L\").filter(ImageFilter.FIND_EDGES).filter(ImageFilter.Kernel((3, 3), (9, -3, -1, -1, 8, -1, 8, -1, -1), 1, 10)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "size1 = pic1.size\n",
    "size2 = pic2.size\n",
    "\n",
    "if size1 > size2: #make sizes of pics the same\n",
    "    pic2 = pic2.resize(size1)\n",
    "elif size2 > size1:\n",
    "    pic1 = pic1.resize(size2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "pics = ImageChops.screen(pic1, pic2) #Mix the pics!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 3065184 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=L size=1600x2136 at 0x7FBB49667AC8>"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 3065184 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=L size=1600x2136 at 0x7FBB4967C400>"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pics = pics.save('mix.jpg') #Save the mix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
