{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Introduction\n\nWhat is Catheter and Line Position?\n\n![Image taken from Wikipedia](https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Blausen_0181_Catheter_CentralVenousAccessDevice_NonTunneled.png/280px-Blausen_0181_Catheter_CentralVenousAccessDevice_NonTunneled.png)\nCVC also known as central venous catheter is a catheter placed into a large vein. Catheters are devices which can be inserted in the body to treat diseases or perform a surgerical procedures.\n\nWhen these lines and tubes are malpositioned patients can suffer from several problems.\n"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport os\nimport cv2\nimport plotly.graph_objects as go\nimport plotly.express as px\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"BASE_DIR = \"../input/ranzcr-clip-catheter-line-classification/\"\ndf_train = pd.read_csv(os.path.join(BASE_DIR, \"train.csv\"), index_col=0)\ndf_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.index.nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = df_train.iloc[:, :-1].sum()\n\nfig = go.Figure(data=[\n    go.Pie(labels=data.index, values=data.values)\n])\n\nfig.update_layout(title='Data distribution')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import random\nfig = go.Figure()\n\nfor col in data.index:\n    \n    random_number = random.randint(0, 16777215)\n    hex_number = str(hex(random_number))\n    hex_number = '#' + hex_number[2:]\n    fig.add_trace(go.Histogram(\n        x=df_train[col],\n        histnorm='percent',\n        name=col,\n        marker_color=hex_number,\n        opacity=0.75\n    ))\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"annot = pd.read_csv(os.path.join(BASE_DIR, \"train_annotations.csv\"))\nannot.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport ast\nplt.show(block=False)\ndef image_plot(images, labels, datas):\n    plt.figure(figsize=(16, 8))\n    for ind, (image, label, data) in enumerate(zip(images, labels, datas)):\n        path = os.path.join(BASE_DIR, \"train\", image + \".jpg\")\n        req_image = cv2.imread(path)\n        req_image = cv2.cvtColor(req_image, cv2.COLOR_BGR2RGB)\n        data = np.array(ast.literal_eval(data))\n        plt.subplot(2, 2, ind+1)\n        plt.imshow(req_image)\n        plt.title(f\"Class: {label}\", fontsize=12)\n        plt.subplot(2, 2, ind+3)\n        plt.imshow(req_image)\n        plt.plot(data[:, 0], data[:, 1])\n        plt.title(f\"Class: {label}\", fontsize=12)\n        plt.axis(\"off\")\n    \n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for col in data.index:\n    df = annot.loc[annot['label'] == col]\n\n    image_plot(df.sample(2)['StudyInstanceUID'].values, df.sample(2)['label'].values, df.sample(2)['data'])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Conclusions\n\n1. Imbalance dataset observed with 42% being CVC - Normal\n2. Images are of varying size with some being too small in comparison to others.\n3. Some images even have lines flowing out of the scaned portion."}],"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}