{"cells":[{"metadata":{},"cell_type":"markdown","source":"## ETT & bifurcation visualization\n\nThis notebook uses external information about tracheal bifurcation (coming from https://www.kaggle.com/raddar/ranzcr-clip-tracheal-bifurcation). Bifurcation is a point in trachea, where it splits into left and right lungs. ETT is considered to be placed normal, if the ETT end point is above bifurcation point, and abnormal - if below bifurcation point. So having both ETT end point and bifurcation point can directly help to estimate if `ETT - Abnormal` or not. This is especially important in this competition, as only ~70 abnormal cases are available in training set."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import ast\nimport numpy as np\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nctr = pd.read_csv('../input/ranzcr-clip-tracheal-bifurcation/RANZCR_CLiP_tracheal_bifurcation.csv')\ntrain = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/train.csv')\ntrain_ann = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/train_annotations.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"normal_uid = train.loc[train['ETT - Normal']==1,'StudyInstanceUID'].tolist()\nabnormal_uid = train.loc[train['ETT - Abnormal']==1,'StudyInstanceUID'].tolist()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"def plot_xray(StudyInstanceUID, label):\n    \"\"\"\n    intubation as green\n    bifurcation as red\n    \"\"\"\n    img = cv2.imread('../input/ranzcr-clip-catheter-line-classification/train/'+StudyInstanceUID+'.jpg')\n    bifurcation = ast.literal_eval(ctr.loc[ctr.StudyInstanceUID==StudyInstanceUID,'tracheal_bifurcation'].values[0])\n    intubation = ast.literal_eval(train_ann.loc[(train_ann.StudyInstanceUID==StudyInstanceUID) & (train_ann.label==label),'data'].values[0])[0]\n    img = cv2.circle(img, tuple(bifurcation), 50, (255,0,0), 10)\n    img = cv2.circle(img, tuple(intubation), 50, (0,255,0), 10)\n    plt.figure(figsize=(16,16))\n    plt.imshow(img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# bifurcation detected correctly\nplot_xray(normal_uid[9],'ETT - Normal')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# model failed to detect bifurcation correctly\nplot_xray(normal_uid[3],'ETT - Normal')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# ETT is way too deep - abnormality is obvious\nplot_xray(abnormal_uid[16],'ETT - Abnormal')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# incorrect label in training data - should be CVC - Abnormal\nplot_xray(abnormal_uid[9],'ETT - Abnormal')","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}