{"cells":[{"metadata":{"_uuid":"4d7d0968-14cd-4276-96f6-3064decfe93d","_cell_guid":"b847c83e-c77d-45d0-b162-17cfe54c9ad3","trusted":true},"cell_type":"code","source":"import pandas\nimport os\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nimport random","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PATH = \"../input/ranzcr-clip-catheter-line-classification/\"\nTRAIN_PATH = PATH + \"train/\"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Class Distribution"},{"metadata":{"trusted":true},"cell_type":"code","source":"labels = pandas.read_csv(PATH + \"train.csv\")\nprint(\"Number of images in dataset:\", len(labels))\ncategoryTotals = np.sum(labels.drop([\"StudyInstanceUID\", \"PatientID\"], axis=1))\nprint(\"Labels:\\n\", categoryTotals)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"categoryTotals = np.sum(labels.drop([\"StudyInstanceUID\", \"PatientID\"], axis=1))\nprint(\"Labels:\\n\", categoryTotals)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"categoryTotals.plot.bar()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Image Sizes"},{"metadata":{"trusted":true},"cell_type":"code","source":"widths = []\nheights = []\n\nfor imgName in os.listdir(TRAIN_PATH):\n    img = Image.open(TRAIN_PATH + imgName)\n    w, h = img.size\n    widths.append(w)\n    heights.append(h)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.suptitle(\"Image Widths\")\nplt.hist(widths, bins=10)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.suptitle(\"Image Heights\")\nplt.hist(heights, bins=10)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Sample Images By Class"},{"metadata":{"trusted":true},"cell_type":"code","source":"def displaySampleClassImages(className):\n    numImgs = 6\n    ids = labels[labels[className]==1][\"StudyInstanceUID\"] #ids belonging to class\n    sampleImgIds = ids.sample(numImgs).to_numpy()\n    \n    fig = plt.figure(figsize=(12,8))\n    cols = 3\n    rows = 2\n    \n    for i in range(1, numImgs+1):\n        fig.add_subplot(rows, cols, i)\n        #image needs converting to display as black and white\n        img = Image.open(TRAIN_PATH + sampleImgIds[i-1] + \".jpg\").convert(\"RGB\")\n        plt.imshow(img)\n    \n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ETT - Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"ETT - Abnormal\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ETT - Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"ETT - Borderline\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ETT - Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"ETT - Normal\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT - Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"NGT - Abnormal\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT - Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"NGT - Borderline\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT - Incompletely Imaged"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"NGT - Incompletely Imaged\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT - Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"NGT - Normal\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### CVC - Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"CVC - Abnormal\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### CVC - Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"CVC - Borderline\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### CVC - Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"CVC - Normal\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Swan Ganz Catheter Present"},{"metadata":{"trusted":true},"cell_type":"code","source":"displaySampleClassImages(\"Swan Ganz Catheter Present\")","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}