{"cells":[{"metadata":{},"cell_type":"markdown","source":"# RANZCR CLiP - Catheter and Line Position Challenge"},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nimport os\nimport json\nimport cv2\nimport matplotlib.pyplot as plt\n\nplt.rcParams[\"figure.figsize\"] = (30,10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"base_folder='../input/ranzcr-clip-catheter-line-classification'\nimage_folder='../input/ranzcr-clip-catheter-line-classification/train'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train=pd.read_csv(os.path.join(base_folder, 'train.csv'))\ndf_mask=pd.read_csv(os.path.join(base_folder, 'train_annotations.csv'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_mask.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_NGT_ab=df_mask[df_mask['label']=='NGT - Abnormal'].reset_index(drop=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_NGT_ab","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def showing_img(df, index):\n    print (df.iloc[index].StudyInstanceUID)\n    data=df.iloc[index]['data']\n    coors=json.loads(data)\n    images=cv2.imread(os.path.join(image_folder, df.iloc[index]['StudyInstanceUID']+'.jpg'),0)\n    images=cv2.cvtColor(clahe.apply(images),cv2.COLOR_GRAY2RGB)\n\n    images_ori=images.copy()\n    h,w=images.shape[0:2]\n    blue = (0, 0, 255)\n    for n, j in enumerate(coors):\n        if n != len(coors)-1:\n            print (coors[n])\n            cv2.line(images, tuple(coors[n]), tuple(coors[n+1]), blue, 3)\n    \n    plt.subplot(121)\n    plt.imshow(images_ori)\n    plt.subplot(122)\n    plt.imshow(images)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Before we start, please check out domain knowledge from dr. Konya's great article (https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/204790)"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# The abnormal tip position of nasogastric tube\n    1. TOO shallow - almost\n    2. U shaped - a few\n    3. Knotted - one"},{"metadata":{},"cell_type":"markdown","source":"# 1. TOO shallow example - almost"},{"metadata":{"trusted":true},"cell_type":"code","source":"showing_img(df_NGT_ab, 3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The tip of nasogatric tube is located in mid-esophagus (superior to the diaphragm)."},{"metadata":{},"cell_type":"markdown","source":"# 2. U shaped example - A few"},{"metadata":{"trusted":true},"cell_type":"code","source":"showing_img(df_NGT_ab, 43)\n\n#43, 51, 57, 79, 86, 96, 100, 106","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The nasogastric tube is showing U-shape."},{"metadata":{},"cell_type":"markdown","source":"# 3. Knotted - one"},{"metadata":{"trusted":true},"cell_type":"code","source":"showing_img(df_NGT_ab, 18)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"There are only 107 NGT-abnormal cases (total 111, wrong 4)\n\nIt is realatively small datasets to learn abnormal NGT position."},{"metadata":{},"cell_type":"markdown","source":"**Wrong annotations - NOT NGT**\n\n1.2.826.0.1.3680043.8.498.12545979153892772426852721449004507757\n1.2.826.0.1.3680043.8.498.75269816256944932004789976844599885553\n1.2.826.0.1.3680043.8.498.11935284122896798228836385959451625327\n1.2.826.0.1.3680043.8.498.83574817573978660270935463700320068005\n"},{"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}