{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport pydicom\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tqdm import tqdm","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_path='/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train'\ntest_path='/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/test'\ntrain_df=pd.read_csv('/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train.csv')\nsample_sub_df=pd.read_csv('/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/sample_submission.csv')\ntrain_df.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.head(10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data=train_df['class_name'].value_counts()\ndata","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pie,ax=plt.subplots(figsize=[10,10])\nlbl=data.keys()\nplt.pie(x=data,autopct='%1.1f%%',labels=lbl, pctdistance=0.6)\nplt.title(\"Class Distribution\", fontsize=14);","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Plotting**\n>Plot xray with bounding boxes"},{"metadata":{"trusted":true},"cell_type":"code","source":"bbox_classes=[]\nimage_ids=train_df['image_id'].unique()\ncolumns=['class_name','x_min','y_min','x_max','y_max']\nfor id_ in tqdm(image_ids):\n    bbox_classes.append(train_df[columns][train_df['image_id']==id_].values)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def plot_xray(image_id,bbox):\n    global class_names\n    class_names=list(train_df['class_name'].unique())\n    colors = plt.cm.hsv(np.linspace(0, 1, len(class_names))).tolist()\n    fig=plt.figure(figsize=(10,10))\n    current_axis = plt.gca()\n    img=pydicom.read_file(os.path.join(train_path,image_id+'.dicom')).pixel_array\n    plt.imshow(img,cmap='gray')\n    for box in bbox:\n        xmin=box[1]\n        ymin=box[2]\n        xmax=box[3]\n        ymax=box[4]\n        label=box[0]\n        color = colors[class_names.index(label)]\n        current_axis.add_patch(plt.Rectangle((xmin, ymin), xmax-xmin, ymax-ymin, \n                                             color=color, fill=False, linewidth=2))\n        \n        current_axis.text(xmin, ymin, label, size='x-large', \n                          color='white', bbox={'facecolor':'green', 'alpha':1.0})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_xray(image_ids[8],bbox_classes[8])\nplot_xray(image_ids[6],bbox_classes[6])","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}