{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "82d16f53-72e8-fa64-0a84-9c4ee2a70ecc"
      },
      "source": [
        "This is my first notebook, I hope this can help your work.  And some codes are forked by     [Intel cervical cancer EDA](https://www.kaggle.com/poonaml/intel-mobileodt-cervical-cancer-screening/intel-cervical-cancer-eda/run/1014556).  \n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "6a780865-36fb-45c0-8f19-76cba1004d3e"
      },
      "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",
        "from PIL import Image\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "import seaborn as sns\n",
        "import os\n",
        "from scipy.misc import imread\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": "markdown",
      "metadata": {
        "_cell_guid": "c6488d08-9a91-ca29-7bce-9648ce7ff27d"
      },
      "source": [
        "## Number of Images"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3fec8729-ba72-ccfc-71bf-30249b82c6bc"
      },
      "outputs": [],
      "source": [
        "sub_folders = check_output([\"ls\", \"../input/train/\"]).decode(\"utf8\").strip().split('\\n')\n",
        "count_dict = {}\n",
        "for sub_folder in sub_folders:\n",
        "    num_of_files = len(check_output([\"ls\", \"../input/train/\"+sub_folder]).decode(\"utf8\").strip().split('\\n'))\n",
        "    print(\"{0} photos of cervix type {1} \".format(num_of_files, sub_folder))\n",
        "\n",
        "    count_dict[sub_folder] = num_of_files\n",
        "    \n",
        "plt.figure(figsize=(12,4))\n",
        "sns.barplot(list(count_dict.keys()), list(count_dict.values()), alpha=0.8)\n",
        "plt.xlabel('Cervix types', fontsize=12)\n",
        "plt.ylabel('Number of Images', fontsize=12)\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "5e11c83f-a834-db9f-9204-e3ea44eb118c"
      },
      "source": [
        "## Sizes of images"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "b76acec0-eeb6-6812-c791-747070e7b021"
      },
      "outputs": [],
      "source": [
        "train_path = \"../input/train/\"\n",
        "sub_folders = check_output([\"ls\", train_path]).decode(\"utf8\").strip().split('\\n')\n",
        "different_file_sizes = {}\n",
        "for sub_folder in sub_folders:\n",
        "    file_names = check_output([\"ls\", train_path+sub_folder]).decode(\"utf8\").strip().split('\\n')\n",
        "    for file_name in file_names:\n",
        "        im_array = imread(train_path+sub_folder+\"/\"+file_name)\n",
        "        size = \"_\".join(map(str,list(im_array.shape)))\n",
        "        different_file_sizes[size] = different_file_sizes.get(size,0) + 1\n",
        "\n",
        "plt.figure(figsize=(12,4))\n",
        "sns.barplot(list(different_file_sizes.values()), list(different_file_sizes.keys()), alpha=0.8)\n",
        "plt.ylabel('Image size', fontsize=12)\n",
        "plt.xlabel('Number of Images', fontsize=12)\n",
        "plt.title(\"Image sizes present in train dataset\")\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "d5107e99-2ded-189c-ce5f-7d63511c64c9"
      },
      "source": [
        "I think in these pictures, the size of (4128,3096) is same to (3096,4218). This doesn't change the means of picture. So I uodate this code."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "87e93fb8-5327-39dd-a669-6a81a49df937"
      },
      "outputs": [],
      "source": [
        "train_path = \"../input/train/\"\n",
        "sub_folders = check_output([\"ls\", train_path]).decode(\"utf8\").strip().split('\\n')\n",
        "different_file_sizes = {}\n",
        "for sub_folder in sub_folders:\n",
        "    file_names = check_output([\"ls\", train_path+sub_folder]).decode(\"utf8\").strip().split('\\n')\n",
        "    for file_name in file_names:\n",
        "        img_path = train_path+sub_folder+\"/\"+file_name\n",
        "        with Image.open(img_path) as img:\n",
        "            (width, heigh) = img.size\n",
        "            if width < heigh:\n",
        "                size = str(heigh) + \"x\" + str(width)\n",
        "            else:\n",
        "                size = str(width) + \"x\" + str(heigh)\n",
        "            different_file_sizes[size] = different_file_sizes.get(size,0) + 1\n",
        "\n",
        "plt.figure(figsize=(12,4))\n",
        "sns.barplot(list(different_file_sizes.values()), list(different_file_sizes.keys()), alpha=0.8)\n",
        "plt.ylabel('Image size', fontsize=12)\n",
        "plt.xlabel('Number of Images', fontsize=12)\n",
        "plt.title(\"Image sizes present in train dataset\")\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "6a9319a9-dccd-f888-88bc-e0a1266163fc"
      },
      "outputs": [],
      "source": [
        "test_path = \"../input/test/\"\n",
        "sub_folders = check_output([\"ls\", test_path]).decode(\"utf8\").strip().split('\\n')\n",
        "different_file_sizes = {}\n",
        "file_names = check_output([\"ls\", test_path]).decode(\"utf8\").strip().split('\\n')\n",
        "for file_name in file_names:\n",
        "    img_path = test_path+\"/\"+file_name\n",
        "    with Image.open(img_path) as img:\n",
        "        (width, heigh) = img.size\n",
        "        if width < heigh:\n",
        "            size = str(heigh) + \"x\" + str(width)\n",
        "        else:\n",
        "            size = str(width) + \"x\" + str(heigh)\n",
        "        different_file_sizes[size] = different_file_sizes.get(size,0) + 1\n",
        "\n",
        "plt.figure(figsize=(12,4))\n",
        "sns.barplot(list(different_file_sizes.values()), list(different_file_sizes.keys()), alpha=0.8)\n",
        "plt.ylabel('Image size', fontsize=12)\n",
        "plt.xlabel('Number of Images', fontsize=12)\n",
        "plt.title(\"Image sizes present in train dataset\")\n",
        "plt.show()"
      ]
    }
  ],
  "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
}