{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "170daf06-8e8f-f68a-8ed1-43a5d08c00ab"
      },
      "outputs": [],
      "source": [
        "%matplotlib inline\n",
        "\n",
        "import dicom # for reading dicom files\n",
        "import os # for doing directory operations \n",
        "import pandas as pd # for some simple data analysis (right now, just to load in the labels data and quickly reference it)\n",
        "\n",
        "# Change this to wherever you are storing your data:\n",
        "# IF YOU ARE FOLLOWING ON KAGGLE, YOU CAN ONLY PLAY WITH THE SAMPLE DATA, WHICH IS MUCH SMALLER\n",
        "\n",
        "data_dir = '../input/sample_images/'\n",
        "patients = os.listdir(data_dir)\n",
        "labels_df = pd.read_csv('../input/stage1_labels.csv', index_col=0)\n",
        "\n",
        "\n",
        "#image[image == -2000] = 0\n",
        "\n",
        "\n",
        "for patient in patients[:4]:\n",
        "    label = labels_df.get_value(patient, 'cancer')\n",
        "    path = data_dir + patient\n",
        "    \n",
        "    # a couple great 1-liners from: https://www.kaggle.com/gzuidhof/data-science-bowl-2017/full-preprocessing-tutorial\n",
        "    slices = [dicom.read_file(path + '/' + s) for s in os.listdir(path)]\n",
        "    slices.sort(key = lambda x: int(x.ImagePositionPatient[2]))\n",
        "    print(slices[0].pixel_array.shape, len(slices))\n",
        "\n",
        "#dcm = dicom.read_file(dcm)\n",
        "#image=dcm.pixel_array\n",
        "#dcm.pixel_array.shape"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "d323d372-4607-cd16-ae89-edd250922283"
      },
      "outputs": [],
      "source": [
        "dcm.rows"
      ]
    }
  ],
  "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
}