{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "954c9893-2b38-d23a-4537-6fc3bdbb9bed"
      },
      "source": [
        "# Floorplan\n",
        "In architecture and building engineering, a floor plan is a drawing to scale, showing a view from above, of the relationships between rooms, spaces and other physical features at one level of a structure.\n",
        "\n",
        "In this dataset, the csv do not have the floorplan image info, but we can use a simple code to extract it from the image dataset.\n",
        "\n",
        "![enter image description here][1]\n",
        "\n",
        "\n",
        "  [1]: https://upload.wikimedia.org/wikipedia/commons/9/9a/Sample_Floorplan.jpg"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a6c4c2ee-6cd6-48d8-0a56-5766abc5702e"
      },
      "outputs": [],
      "source": [
        "# This Python 3 environment comes with many helpful analytics libraries installed\n",
        "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n",
        "# For example, here's several helpful packages to load in \n",
        "\n",
        "import numpy as np # linear algebra\n",
        "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
        "\n",
        "# Input data files are available in the \"../input/\" directory.\n",
        "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n",
        "\n",
        "from subprocess import check_output\n",
        "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n",
        "\n",
        "# Any results you write to the current directory are saved as output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "7bc03ddb-a5c4-fefa-9999-edd18d4b4fcf"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "import codecs\n",
        "import subprocess\n",
        "\n",
        "import PIL\n",
        "from PIL import Image\n",
        "from PIL import ImageFile\n",
        "ImageFile.LOAD_TRUNCATED_IMAGES = True\n",
        "\n",
        "# your image path\n",
        "img_dir = '../input/images_sample/'\n",
        "\n",
        "def white_count(img_url):\n",
        "    im = Image.open(img_url)  \n",
        "    w, h = im.size  \n",
        "    colors = im.getcolors(w*h)\n",
        "    return im.getcolors(w*h)[0][0] / (w * h * 1.0)\n",
        "\n",
        "for listing_dir in os.listdir(img_dir):\n",
        "    if len(listing_dir) != 7 or not listing_dir.isdigit():\n",
        "        continue\n",
        "    \n",
        "    for listing_img in os.listdir(img_dir + listing_dir):\n",
        "        if listing_img == '.DS_Store' or listing_img == listing_dir:\n",
        "            continue\n",
        "        white_scale = white_count(img_dir + listing_dir + '/' + listing_img)\n",
        "        if white_scale > 0.6:\n",
        "            print(listing_img, white_scale)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "6fd2759a-0263-6aa9-5362-03ce17b9df84"
      },
      "source": [
        "So let's have a look of this image."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "cd0130f6-6930-94ba-1f93-8cddd49aa2a1"
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n",
        "import matplotlib.image as mpimg\n",
        "\n",
        "plt.figure(figsize = (12, 10))\n",
        "\n",
        "img1 = mpimg.imread('../input/images_sample/6811974/6811974_197bb9515b3d7929c2848e61a050ad1a.jpg')\n",
        "plt.subplot(1, 2, 1)\n",
        "plt.imshow(img1) \n",
        "\n",
        "img2 = mpimg.imread('../input/images_sample/6811958/6811958_bb863a4184a1e085f0c55e0172767abd.jpg')\n",
        "plt.subplot(1, 2, 2)\n",
        "plt.imshow(img2)"
      ]
    }
  ],
  "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.6.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}