|
|
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Open cv library\n",
- "import cv2\n",
- "\n",
- "# matplotlib for displaying the images \n",
- "from matplotlib import pyplot as plt"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "img = cv2.imread('dolphin.jpg')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQQAAAD8CAYAAACRvtrKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9yY9ty3Xm91srIvbe52Te9jV8fA17iZJlQVJJkFVQoVyGUYWCGxQMGHDzBxQ8MDz2X2FPjYLhkQeeSW4guzyriUplURJAFSlSpEiKzWvvu13ePOfsHRFrebDi5H0sSI81IKEn4AaQyJt5z9lnNxErvvWtb30p7s6L8WK8GC8GgP5Nn8CL8WK8GJ+c8SIgvBgvxotxM14EhBfjxXgxbsaLgPBivBgvxs14ERBejBfjxbgZLwLCi/FivBg342cSEETkH4vIN0Xk2yLy3/8sPuPFeDFejJ/+kJ+2DkFEEvDnwD8Efgj8IfBfufvXf6of9GK8GC/GT338LBDCbwLfdvfvuPsG/G/AP/kZfM6L8WK8GD/lkX8Gx3wD+MFHfv4h8O993Bt2d1/yO5/+DO6OiIAD4riDu2PnLxwnEI2IIEBCUFUQQUURARAYyOcGAcn5m8Tv3EEcAXQcK14kOGDuQJyDSHzezREElOfIynFufhQZP8cb3X0cNa7Lz68//47nx5Z4+48fZ7zK3ekOPj7//DLD6e7ny40jS/xDReL+ICCOjffHC+P4Fv9E/Pzh/vxc8Pj9j19pfHm878eHP7+m8S+5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EjClzL5MFBFS6yCZpKBiIJ1NDLwHYjhp7GjuaO/
- "text/plain": [
- "<Figure size 432x288 with 1 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "def printI(img):\n",
- " rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
- " plt.imshow(rgb)\n",
- " \n",
- "def printI2(i1, i2):\n",
- " fig = plt.figure()\n",
- " ax1 = fig.add_subplot(1,2,1)\n",
- " ax1.imshow(cv2.cvtColor(i1, cv2.COLOR_BGR2RGB))\n",
- " ax2 = fig.add_subplot(1,2,2)\n",
- " ax2.imshow(cv2.cvtColor(i2, cv2.COLOR_BGR2RGB))\n",
- " \n",
- "printI(img)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAC5CAYAAADTVX+OAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9W6xl2XWe940xL2vtvc85de0rmxdJJGU5ti6RLDkJAitIYihKYr0FToAAebFektcges9LXgMEMGAgRuL4wUEAI0EQG0qcQLAcXSxHFimJFO8im+xuVlVX1bntvdaac46Rh7mqmrTFc9oyW90iz9+orn12zbNue+2xxhzz//8h7s4NbnCDG9zgewv6fh/ADW5wgxvc4LuPm+B+gxvc4Abfg7gJ7je4wQ1u8D2Im+B+gxvc4Abfg7gJ7je4wQ1u8D2Im+B+gxvc4Abfg3hPgruI/JyIfE5Evigiv/Re7OMGN3g/cHNv3+BPC+S7zXMXkQB8Hvh3ga8DvwX8x+7+me/qjm5wgz9h3NzbN/jThPcic/9p4Ivu/mV3X4C/A/zCe7CfG9zgTxo39/YN/tQgvgfb/BD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BMniqCyMkrMQAN7yywVEChOL+/YynYR1kXMBhRiqGge2B8maI66kmMkxkSgIW3N1r0/pM0Maw1RxRVchForLpBDRsQwWl8oViHEyBAT0R33Bu7kNPZZjQj2bCZgTiqdjaHRqaLMc6/FiwveK0Y3uMH3HT4Qwd1EOFPBEerxDiOQW8PMmEqjBucAqCtRElEgG6RFSFYYtBElUa0HjWIwNada6+UVArM3FhF03pObksNaMzYhiGKtUYNiIpwMA/fubJncmd1YTFnWrFS
- "text/plain": [
- "<Figure size 432x288 with 2 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "def pixelate(img, w, h):\n",
- " height, width = img.shape[:2]\n",
- "\n",
- " # Resize input to \"pixelated\" size\n",
- " temp = cv2.resize(img, (w, h), interpolation=cv2.INTER_LINEAR)\n",
- "\n",
- " # Initialize output image\n",
- " return cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST)\n",
- "\n",
- "img16 = pixelate(img, 16, 16)\n",
- "\n",
- "printI2(img, img16)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAC5CAYAAADTVX+OAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9XYwlSXbf9zsRkZn3q7q7pqd7ZnZmlrtLLmnRIimKNGkSICxLNiAJBvhiUJYAwzIME4atB8MGbMEvfvWr4QfBhCnQMgRKsvUgP9ASbEHfNE2KFLnkktzlcr/mq6dn+qO6qu69mRkRxw8nMm/mrZ6PXe587KLOoKb6ZmVGRsaNPHHif/7nHFFVruVaruVaruU7S9xH3YFruZZruZZr+dbLtXK/lmu5lmv5DpRr5X4t13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1ezu3rj1NXdHFxNvn5qMR8QRxNF44WQSzxFNGVTmPmYu+J+XEvmC9mxsNTRPYtT3n2z0hKy+cdwjKK//y17j3m79KzInLbo93jhfuPotz5hwPweMr4ZOf/BQAZw8f89bX/pD69a9x8dv/H2GxJP/Uv4OrKpaf/Ayb7/lj5gMo71xOEc2ZnCJ93yEItfeA4MkMZkQq83mfe3pVogpddmSFy84UrA/245zg62IGhQC+ohbTG6qQu4jh2Q7vBO+gCeYQPe8jqop3Hi8r+x6SzUfvwwjLZM04VUJ5D2xn5Yk58+TCxlVTMphNIeaAE8c6rBBskQ7mWSa7TWnDowjiFOdtEeuTjVNS29F5LzR1RR2OJv9EPjKH6rFMFYIZNnPlYgahzs7T4dzjtt7jmAw/s3vKzCn
- "text/plain": [
- "<Figure size 432x288 with 2 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "img32 = pixelate(img, 32, 32)\n",
- "img64 = pixelate(img, 64, 64)\n",
- "\n",
- "printI2(img32, img64)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQQAAAD8CAYAAACRvtrKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAARFklEQVR4nO3dbYxc5XnG8f81M/uGjVm/gOt4nZgIV5SqDdBt4ohKjUCRgKLAB5qCouBGlvyFSkSKlEIrNWoVqcmXkESqoqI6ihOlIWkSCQshIWqooqoKiQkvAVzCgkKxZXAwfgGvvbsz5+6HefZhMMa79s48MytdP2m05zzn7D737M5cc87Z2b0VEZiZAdT6XYCZDQ4HgpllDgQzyxwIZpY5EMwscyCYWdaTQJB0vaQXJE1JursXc5hZ96nb70OQ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rMemMx70PYAOySVKcdID+KiAclPQ/cL+nLwJPAzrT/TuB7kqaAN4HbelC3mfXAgoEQEc8AV51h/GXa1xNOHz8F/GVXqjOzovzWZTPLHAhmljkQzCxzIJhZ5kAws8yBYGaZA8HMMgeCmWUOBDPLHAhmljkQzCxzIJhZ5kAws8yBYGaZA8HMMgeCmWUOBDPLBqKVW1UFb82UaXc2PduCGIaqTKuIFXNw0aky7c7mGkFrpFAHLIDZaLc9K6A52+TUyZNlJhPUhkeKdW6qRwtR5vG/kIEIhFYEJ2bLPGlOzDaJagiizA/7glkYny3zJJ2p4FSrWaSVWxDMVe2OPSXEzBwzM6cKzQYjw0PU6/Uic0WthQbimehTBjPr4EAws8yBYGaZA8HMMgeCmWUOBDPLHAhmljkQzCxzIJhZ5kAws8yBYGa
- "text/plain": [
- "<Figure size 432x288 with 1 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "img8 = pixelate(img, 8, 8)\n",
- "printI(img8)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [],
- "source": [
- "import skimage\n",
- "from sklearn.cluster import KMeans\n",
- "from numpy import linalg as LA\n",
- "import numpy as np"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "def colorClustering(idx, img, k):\n",
- " clusterValues = []\n",
- " for _ in range(0, k):\n",
- " clusterValues.append([])\n",
- " \n",
- " for r in range(0, idx.shape[0]):\n",
- " for c in range(0, idx.shape[1]):\n",
- " clusterValues[idx[r][c]].append(img[r][c])\n",
- "\n",
- " imgC = np.copy(img)\n",
- "\n",
- " clusterAverages = []\n",
- " for i in range(0, k):\n",
- " clusterAverages.append(np.average(clusterValues[i], axis=0))\n",
- " \n",
- " for r in range(0, idx.shape[0]):\n",
- " for c in range(0, idx.shape[1]):\n",
- " imgC[r][c] = clusterAverages[idx[r][c]]\n",
- " \n",
- " return imgC"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "def segmentImgClrRGB(img, k):\n",
- " \n",
- " imgC = np.copy(img)\n",
- " \n",
- " h = img.shape[0]\n",
- " w = img.shape[1]\n",
- " \n",
- " imgC.shape = (img.shape[0] * img.shape[1], 3)\n",
- " \n",
- " #5. Run k-means on the vectorized reponses X to get a vector of labels (the clusters); \n",
- " # \n",
- " kmeans = KMeans(n_clusters=k, random_state=0).fit(imgC).labels_\n",
- " \n",
- " #6. Reshape the label results of k-means so that it has the same size as the input image\n",
- " # Return the label image which we call idx\n",
- " kmeans.shape = (h, w)\n",
- "\n",
- " return kmeans"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQQAAAD8CAYAAACRvtrKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9WYxlSXrf94uIs981l1qyunqZnhnOyqFNmqQkUgJhW7AsyKAhwLLlF9swwBfr3Xzzq14N2DBMGIItGLBkP8kPNCxYkrVYIjlDaqiZnu7p6bWqqyort7ufPSL8EOecvDfzZlZWTTdZI9QHzHTlXc4595yIL774f//v/wlrLa/slb2yVwYg/7Qv4JW9slf28tgrh/DKXtkr6+yVQ3hlr+yVdfbKIbyyV/bKOnvlEF7ZK3tlnb1yCK/slb2yzr4QhyCE+EtCiB8LIT4QQvz2F3GOV/bKXtnnb+Lz5iEIIRTwPvAXgc+A7wJ/3Vr7o8/1RK/slb2yz92+iAjhV4APrLUfWWtL4O8Av/kFnOeVvbJX9jmb9wUc8zXg4drfnwG/et0X4vGeHd57nW2xirUGa8FYgwXEhfeldD5NIJBCbD3GVXbxWBvnveaz153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slSine+cPvMfjJ+3zll36Zg1/7DYg3wcRutW3uleLz51Pc1F7kWRd12WwdbMchGIQ9pBDMi2U31jylkELiS+9aZ9Mep92jSyE3Jl5W5Rhrm3Rle5ztWJknFZ48X1zaLMUL406NtVwNbQVZ6RakZ6UfXxqHsD5xPKnoB0m3xhprWJUZaZV1nxEIgsajxkH0wvu
- "text/plain": [
- "<Figure size 432x288 with 1 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "def kMeansImage(image, k):\n",
- " idx = segmentImgClrRGB(image, k)\n",
- " return colorClustering(idx, image, k)\n",
- "\n",
- "printI(kMeansImage(img, 5))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQQAAAD8CAYAAACRvtrKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAaMElEQVR4nO3da4xc5Z3n8e//nKrqmy/tbtvtS9uYiyFxEiCBJOQyo4gou4Rkh0ibC5lZhh0h8SYjZaSRZpNdaUcrzYvJm2Ey0io77JANZKIw2cxIsNlIWRYym81qkmASAgQwNmCwTdvtO9juS9U5/31Rx2ca91PVXd11OQW/j1Ry1fOcU/Xvbvevz3meczF3R0QEIOp1ASJSHAoEEckpEEQkp0AQkZwCQURyCgQRyXUkEMzsFjPbZ2YHzOwrnfgMEWk/a/dxCGYWAy8AnwAOA48DX3T3Z9v6QSLSdp3YQvgAcMDdX3L3eeBB4LYOfI6ItFmpA++5HTi04PVh4IPNVhgcHfORLds7UMpbT1qtMnvyZMvrRZUKg2NjHahI+s2pfc+ccPdNob5OBMKymNndwN0AIxPb+NR9D/eqlL5yfmqK5x/4by2vt2ZyB1f/7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xcyolMs4iy/OVy7AXYGW4gClcn0asQUpRvX8uXDfzAxRg0uTNZtytFKJuLL4pCmLIyxq/PfQy5Xgz9XjlHh4hFK8eCYhjiOoDJAGZhk8SiiXS8GfaZqkJA0GB5MkZb7B1x3HjackV0qBsExHfvJ/Gl43Ma02ngteieGhQW647p3Bvn45qWl2z3Wka1q7TuDrB1/mpf96b7jT0/q8e0Da5Kqmo7uvZue/+Je
- "text/plain": [
- "<Figure size 432x288 with 1 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "printI(kMeansImage(img32, 3))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "image/png": "iVBORw0KGgoAAAANSUhEUgAABBQAAAFHCAYAAAARPR9iAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9W6xs2XWe940x51yrqva59elmU2STEimRuplSRF0i2Qjs2JYBxwKkAAkcJ0CQhyBGHvIaJEAegjwmMOIgShTAQPIUGAECBIjjSHIQyZZgQYmoWIYkk5JI0SabfVXfzjl776q11pxj5GHMqtNNs2s3rSbZItdPbJ5zqlettWrddo1/jP//xd1ZsWLFihUrVqxYsWLFihUrVqz4aqDf6B1YsWLFihUrVqxYsWLFihUrVvzJw0oorFixYsWKFStWrFixYsWKFSu+aqyEwooVK1asWLFixYoVK1asWLHiq8ZKKKxYsWLFihUrVqxYsWLFihUrvmqshMKKFStWrFixYsWKFStWrFix4qvGSiisWLFixYoVK1asWLFixYoVK75qfE0IBRH5yyLy+yLyORH5T78W21ixYsWKFeexPotXrFix4huL9Tm8YsWKb3aIu7+7KxRJwB8Afwn4EvAp4N9290+/qxtasWLFihVvi/VZvGLFihXfWKzP4R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3yoXF9dcZgmHraFSp/e6N1EFSGnKJ6PpFKuxkiipN6R6iSVESO9SwtSYaoxeaBJSP38qL5J+mJd+mAJIWEuIXEBkirm0kdk431jEpIA5qg6KlH
- "text/plain": [
- "<Figure size 1296x432 with 3 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "def printI3(i1, i2, i3):\n",
- " fig = plt.figure(figsize=(18,6))\n",
- " ax1 = fig.add_subplot(1,3,1)\n",
- " ax1.imshow(cv2.cvtColor(i1, cv2.COLOR_BGR2RGB))\n",
- " ax2 = fig.add_subplot(1,3,2)\n",
- " ax2.imshow(cv2.cvtColor(i2, cv2.COLOR_BGR2RGB))\n",
- " ax3 = fig.add_subplot(1,3,3)\n",
- " ax3.imshow(cv2.cvtColor(i3, cv2.COLOR_BGR2RGB))\n",
- " plt.savefig('trifecta.png')\n",
- "printI3(img, img32, kMeansImage(img32, 3))"
- ]
- }
- ],
- "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.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
- }
|