{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import seaborn as sns","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# train_annotation"},{"metadata":{"trusted":true},"cell_type":"code","source":"seg_df = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/train_annotations.csv')\nseg_df","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## label Bar Plot"},{"metadata":{"trusted":true},"cell_type":"code","source":"seg_df['label'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.rcParams[\"figure.figsize\"] = (25, 10)\nsns.barplot(x=seg_df['label'].value_counts().index.values, y=seg_df['label'].value_counts())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## annotation visualization"},{"metadata":{"trusted":true},"cell_type":"code","source":"from PIL import Image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_point(chosen, seg_df):\n    points = []\n    for i, point in enumerate(seg_df.iloc[chosen,2].split('],')):\n        if i==len(seg_df.iloc[chosen,2].split('],'))-1:\n            xy = tuple([int(x) for x in point[2:-2].split(', ')])\n            print(xy)\n            points.append(xy)\n        else:\n            xy = tuple([int(x) for x in point[2:].split(', ')])\n            print(xy)\n            points.append(xy)\n    return points","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from PIL import ImageDraw\n\ndef draw_point(points, img):\n    draw = ImageDraw.Draw(img)\n    draw.line(points, fill=255, width=5)\n#     for point in points:\n#         draw.ellipse([(point[0]-2, point[1]-2), (point[0]+2, point[1]+2)], fill='white')\n    plt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# CVC - Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='CVC - Normal'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# CVC - Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='CVC - Borderline'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# CVC - Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='CVC - Abnormal'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# ETT - Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='ETT - Normal'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# ETT - Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='ETT - Borderline'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# ETT - Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='ETT - Abnormal'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# NGT - Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='NGT - Normal'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# NGT - Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='NGT - Borderline'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# NGT - Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='NGT - Abnormal'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# NGT - Incompletely Imaged"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='NGT - Incompletely Imaged'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Swan Ganz Catheter Present"},{"metadata":{"trusted":true},"cell_type":"code","source":"chosen = seg_df.loc[seg_df['label']=='Swan Ganz Catheter Present'].index.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = Image.open(f'../input/ranzcr-clip-catheter-line-classification/train/{seg_df.iloc[chosen,0]}.jpg')\nplt.imshow(img, cmap='gray')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"points = get_point(chosen, seg_df)\ndraw_point(points, img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}