{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# SIIM-FISABIO-RSNA COVID-19 Detection\n\n\n![](https://axisimagingnews.com/wp-content/uploads/2020/10/COVID19.jpg)\n\nSource: https://axisimagingnews.com/imaging-news/associations/siim-fisabio-rsna-host-machine-learning-challenge-covid-19-detection-localization","metadata":{}},{"cell_type":"markdown","source":"**NEGATIVE FOR PNEUMONIA**\n\n    - No lung opacities\n\n**TYPICAL APPEARANCE**\n\n    - Multifocal bilateral, peripheral opacities with rounded morphology, lower lung–predominant distribution\n\n**INDETERMINATE APPEARANCE**\n\n    - Absence of typical findings AND unilateral, central or upper lung predominant distribution\n\n**ATYPICAL APPEARANCE**\n\n    - Pneumothorax, pleural effusion, pulmonary edema, lobar consolidation, solitary lung nodule or mass, diffuse tiny nodules, cavity","metadata":{}},{"cell_type":"markdown","source":"# Content:\n\n**1. Import Libraries**\n\n**2. Collect data**\n\n**3. Data Exploration**\n\n       * annotation per class\n       * Plot images\n       * exposure.equalize_hist\n     \n**4. Images character with rectangles visualization**\n\n      * Typical Appearance character\n      * Indeterminate Appearance character\n      * Atypical_Appearance character\n      \n**5. Photometric Interpretation of MONOCHROME1 &  MONOCHROME2**\n\n      * Typical Appearance\n              MONOCHROME1\n              MONOCHROME2\n      * Indeterminate Appearance\n              MONOCHROME1\n              MONOCHROME2\n      * Atypical_Appearance\n              MONOCHROME1\n              MONOCHROME2\n      \n**6. Modality**\n\n      * Negative for Pneumonia\n              MONOCHROME1\n                  * CR\n                  * DX\n              MONOCHROME2\n                  * CR\n                  * DX\n\n      * Typical Appearance\n              MONOCHROME1\n                  * CR\n                  * DX\n              MONOCHROME2\n                  * CR\n                  * DX\n      * Indeterminate Appearance\n              MONOCHROME1\n                  * CR\n                  * DX\n              MONOCHROME2\n                  * CR\n                  * DX\n      * Atypical_Appearance\n              MONOCHROME1\n                  * CR\n                  * DX\n              MONOCHROME2\n                  * CR\n                  * DX\n","metadata":{}},{"cell_type":"markdown","source":"# 1. **Import Libraries**","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport glob\nfrom tqdm import tqdm\nimport matplotlib\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm, colors\nfrom functools import reduce\nimport ast\n\nfrom math import *\n\nfrom scipy.linalg import norm\nimport scipy.ndimage\n\nfrom ipywidgets.widgets import *\nimport ipywidgets as widgets\n\nimport plotly\nfrom plotly.graph_objs import *\n#import chart_studio.plotly as py\n\nfrom mpl_toolkits.mplot3d import Axes3D\nimport seaborn as sns\nimport cv2\nfrom skimage import io, img_as_float, img_as_ubyte, color, exposure, measure, morphology\nfrom skimage.measure import label, regionprops\n\nimport pydicom\nfrom pydicom.data import get_testdata_file\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nfrom pydicom import dcmread\n\n\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","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:18:05.056157Z","iopub.execute_input":"2021-06-14T06:18:05.056580Z","iopub.status.idle":"2021-06-14T06:18:07.256895Z","shell.execute_reply.started":"2021-06-14T06:18:05.056482Z","shell.execute_reply":"2021-06-14T06:18:07.255523Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **2. Collect data**","metadata":{}},{"cell_type":"markdown","source":" **Reading Files**","metadata":{}},{"cell_type":"code","source":"train_image_level = pd.read_csv('/kaggle/input/siim-covid19-detection/train_image_level.csv')\ntrain_study_level = pd.read_csv('/kaggle/input/siim-covid19-detection/train_study_level.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:18:07.258346Z","iopub.execute_input":"2021-06-14T06:18:07.258696Z","iopub.status.idle":"2021-06-14T06:18:07.323346Z","shell.execute_reply.started":"2021-06-14T06:18:07.258660Z","shell.execute_reply":"2021-06-14T06:18:07.322439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.head(3)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:18:07.325286Z","iopub.execute_input":"2021-06-14T06:18:07.325796Z","iopub.status.idle":"2021-06-14T06:18:07.347521Z","shell.execute_reply.started":"2021-06-14T06:18:07.325751Z","shell.execute_reply":"2021-06-14T06:18:07.346569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_level.head(3)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:07.348970Z","iopub.execute_input":"2021-06-14T06:18:07.349223Z","iopub.status.idle":"2021-06-14T06:18:07.359436Z","shell.execute_reply.started":"2021-06-14T06:18:07.349200Z","shell.execute_reply":"2021-06-14T06:18:07.358583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print( \"'train_image_level's data has \",train_image_level.shape[0], 'samples')\nprint( \"& 'train_study_level's data has \",train_study_level.shape[0], 'samples')\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:07.360733Z","iopub.execute_input":"2021-06-14T06:18:07.361085Z","iopub.status.idle":"2021-06-14T06:18:07.368330Z","shell.execute_reply.started":"2021-06-14T06:18:07.361051Z","shell.execute_reply":"2021-06-14T06:18:07.367299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Merge study csv to image csv.**","metadata":{}},{"cell_type":"code","source":"#Merge study csv to image csv.\ntrain_study_level['StudyInstanceUID'] = train_study_level['id'].apply(lambda x: x.replace('_study', ''))\ntrain_image_level = train_image_level.merge(train_study_level, on='StudyInstanceUID')","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:07.369817Z","iopub.execute_input":"2021-06-14T06:18:07.370155Z","iopub.status.idle":"2021-06-14T06:18:07.397633Z","shell.execute_reply.started":"2021-06-14T06:18:07.370124Z","shell.execute_reply":"2021-06-14T06:18:07.396943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.head(3)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:18:07.398936Z","iopub.execute_input":"2021-06-14T06:18:07.399433Z","iopub.status.idle":"2021-06-14T06:18:07.414606Z","shell.execute_reply.started":"2021-06-14T06:18:07.399395Z","shell.execute_reply":"2021-06-14T06:18:07.413505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Merge image path to the train_image_level dataframe.**","metadata":{}},{"cell_type":"code","source":"# Merge image path to the train_image_level dataframe.\ntrain_dir = '/kaggle/input/siim-covid19-detection/train'\ntest_dir = '/kaggle/input/siim-covid19-detection/test'\n\ntraining_paths = []\n\nfor sid in tqdm(train_image_level['StudyInstanceUID']):\n    training_paths.append(glob.glob(os.path.join(train_dir,sid+\"/*/*\"))[0])\n\ntrain_image_level['path'] = training_paths\n","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:07.417535Z","iopub.execute_input":"2021-06-14T06:18:07.417876Z","iopub.status.idle":"2021-06-14T06:18:28.066267Z","shell.execute_reply.started":"2021-06-14T06:18:07.417844Z","shell.execute_reply":"2021-06-14T06:18:28.065441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Read full text in table\npd.set_option('display.max_colwidth', -1)\ntrain_image_level.head(3)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:28.068033Z","iopub.execute_input":"2021-06-14T06:18:28.068317Z","iopub.status.idle":"2021-06-14T06:18:28.085049Z","shell.execute_reply.started":"2021-06-14T06:18:28.068289Z","shell.execute_reply":"2021-06-14T06:18:28.084457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Read image file (.dcm)**","metadata":{}},{"cell_type":"code","source":"#training_paths = []\nds = pydicom.dcmread(training_paths[0])\nds","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:28.085931Z","iopub.execute_input":"2021-06-14T06:18:28.086277Z","iopub.status.idle":"2021-06-14T06:18:29.189122Z","shell.execute_reply.started":"2021-06-14T06:18:28.086242Z","shell.execute_reply":"2021-06-14T06:18:29.188123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Read DCM files and add DCM conlumns to \"Complete Data\"**","metadata":{}},{"cell_type":"code","source":"def process_dicom(dicom_obj):\n    pixel_data=(0x7fe0, 0x0010) #ignore the pixel data\n    data_dict={}\n    for x in dicom_obj:\n        if x.tag==pixel_data:\n            continue\n        value=dicom_obj[x.tag].value\n        name=x.name\n        data_dict[name]=value\n    return data_dict","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:29.190504Z","iopub.execute_input":"2021-06-14T06:18:29.190899Z","iopub.status.idle":"2021-06-14T06:18:29.196335Z","shell.execute_reply.started":"2021-06-14T06:18:29.190852Z","shell.execute_reply":"2021-06-14T06:18:29.195397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns_reordered = list(train_image_level.columns)\ncomplete_data = train_image_level[columns_reordered]\n\ndicom_dict={}\nneeded_columns=[\"Patient ID\",\"Patient's Sex\",\"Body Part Examined\",\"Imager Pixel Spacing\",\n                \"Photometric Interpretation\",\"Modality\"]\n# \"Study Instance UID\",\"Study ID\"\n\nfor i,x in tqdm(complete_data.iterrows()):\n    dicom_obj=pydicom.dcmread(x['path'],stop_before_pixels=True)\n    dicom_obj_dict=process_dicom(dicom_obj)\n    for key in dicom_obj_dict:\n        if type(dicom_obj_dict[key])==list:\n            continue\n        if key in needed_columns:\n            if key not in dicom_dict:\n                dicom_dict[key]=[]\n            dicom_dict[key].append(dicom_obj_dict[key])\n            \nfor col in needed_columns:\n    complete_data[col]=dicom_dict[col]\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:18:29.197659Z","iopub.execute_input":"2021-06-14T06:18:29.198057Z","iopub.status.idle":"2021-06-14T06:20:04.615841Z","shell.execute_reply.started":"2021-06-14T06:18:29.198020Z","shell.execute_reply":"2021-06-14T06:20:04.614673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Complete data.**","metadata":{}},{"cell_type":"code","source":"complete_data.head(1)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:20:04.617774Z","iopub.execute_input":"2021-06-14T06:20:04.618087Z","iopub.status.idle":"2021-06-14T06:20:04.637572Z","shell.execute_reply.started":"2021-06-14T06:20:04.618046Z","shell.execute_reply":"2021-06-14T06:20:04.636856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"complete_data.iloc[25:28]","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:20:04.638510Z","iopub.execute_input":"2021-06-14T06:20:04.638783Z","iopub.status.idle":"2021-06-14T06:20:04.665426Z","shell.execute_reply.started":"2021-06-14T06:20:04.638758Z","shell.execute_reply":"2021-06-14T06:20:04.664646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col_grp='StudyInstanceUID'\ndf= complete_data.groupby(col_grp)['id_x'].count() #look double id\ndf.columns = [f'{col_grp}_count'] # create 'StudyInstanceUID_count'\ncomplete_data = complete_data.merge(df.reset_index(), on= col_grp)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:20:04.666643Z","iopub.execute_input":"2021-06-14T06:20:04.666971Z","iopub.status.idle":"2021-06-14T06:20:04.703501Z","shell.execute_reply.started":"2021-06-14T06:20:04.666945Z","shell.execute_reply":"2021-06-14T06:20:04.702593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **3. Data Exploration**","metadata":{}},{"cell_type":"code","source":"study_grp = pd.melt(complete_data, id_vars=list(complete_data.columns)[:1],\n                         value_vars = list(complete_data.columns)[5:9],\n                                           var_name='label', value_name = 'value')\nstudy_grp = study_grp.loc[study_grp['value']!=0]\nstudy_grp = study_grp.groupby('label').sum().sort_values('value', ascending=False).reset_index()\n\nfig,ax = plt.subplots(1,1, figsize=(15,5))\n\nsns.barplot(x='label', y='value', data=study_grp, palette='pastel') \nsns.color_palette('hls')\n\nvalues = list(study_grp['value'])\nfor i, v in enumerate(values):\n    ax.text(i, v+25, '%d' %v, ha='center')\n\nfig.text(0.1,0.9, \"Annotation Per Class = 1\", fontsize=23, fontweight='bold', fontfamily='serif')\nplt.grid(axis='y')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:20:04.704860Z","iopub.execute_input":"2021-06-14T06:20:04.705381Z","iopub.status.idle":"2021-06-14T06:20:04.961439Z","shell.execute_reply.started":"2021-06-14T06:20:04.705341Z","shell.execute_reply":"2021-06-14T06:20:04.960586Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Negative = complete_data[complete_data['Negative for Pneumonia']==1]\nTypical = complete_data[complete_data['Typical Appearance']==1]\nIndeterminate = complete_data[complete_data['Indeterminate Appearance']==1]\nAtypical = complete_data[complete_data['Atypical Appearance']==1]\n\ndata = pd.DataFrame({'Typical Appearance': Typical[\"Patient's Sex\"].value_counts(),\n              'Negative for Pneumonia': Negative[\"Patient's Sex\"].value_counts(),\n              'Indeterminate Appearance': Indeterminate[\"Patient's Sex\"].value_counts(),\n              'Atypical Appearance': Atypical[\"Patient's Sex\"].value_counts()\n             })\ndata_t = data.transpose()\nax = data_t.plot.bar(stacked = True, width=0.8,figsize=(15,5), title=\"Annotation Per Class = 1\")\n\nplt.grid(axis='y')\nplt.xticks(rotation=0)\nplt.show()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:20:04.962407Z","iopub.execute_input":"2021-06-14T06:20:04.962653Z","iopub.status.idle":"2021-06-14T06:20:05.166596Z","shell.execute_reply.started":"2021-06-14T06:20:04.962630Z","shell.execute_reply":"2021-06-14T06:20:05.165675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Plot images**","metadata":{}},{"cell_type":"code","source":"#Linear Rescale\nlabel_appearance = list(complete_data.columns)[5:9]\nrow_img = 3\ncol_img = len(label_appearance)\n\nc= 0\ncolor = 'gray'\nds_pos = [0 for p in range(row_img)]\n\nfig,ax = plt.subplots(row_img,col_img, figsize=(25,row_img*4))\n\nfor i in label_appearance:\n    for r in range(row_img):\n        link = complete_data[complete_data[i] == 1]['path'].iloc[r]\n        ds_pos[r] = pydicom.dcmread(link).pixel_array\n        ax[r,c].imshow(ds_pos[r], cmap=color)\n        \n      \n    ax[0,c].set_title(i, font='Serif', fontsize=20)\n    c +=1","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:20:05.167741Z","iopub.execute_input":"2021-06-14T06:20:05.168044Z","iopub.status.idle":"2021-06-14T06:20:17.950132Z","shell.execute_reply.started":"2021-06-14T06:20:05.168020Z","shell.execute_reply":"2021-06-14T06:20:17.949220Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**exposure.equalize_hist**","metadata":{}},{"cell_type":"code","source":"#plot images under exposure.equalize_hist\nlabel_appearance = list(complete_data.columns)[5:9]\nrow_img = 3\ncol_img = len(label_appearance)\n\nc= 0\ncolor = 'gray'\nds_pos = [0 for p in range(row_img)]\n\nfig,ax = plt.subplots(row_img,col_img, figsize=(25,row_img*4))\n\nfor i in label_appearance:\n    for r in range(row_img):\n        link = complete_data[complete_data[i] == 1]['path'].iloc[r]\n        ds_pos[r] = pydicom.dcmread(link).pixel_array\n        img = exposure.equalize_hist(ds_pos[r])\n              \n        \n        ax[r,c].imshow(img, cmap=color)\n      \n    ax[0,c].set_title(i, font='Serif', fontsize=20)\n    c +=1","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:20:17.951103Z","iopub.execute_input":"2021-06-14T06:20:17.951460Z","iopub.status.idle":"2021-06-14T06:20:35.274645Z","shell.execute_reply.started":"2021-06-14T06:20:17.951434Z","shell.execute_reply":"2021-06-14T06:20:35.273765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **4. Images character with rectangles visualization**","metadata":{}},{"cell_type":"code","source":"complete_xy = complete_data[complete_data['label'] != 'none 1 0 0 1 1']\nTypical_Appearance = complete_xy[complete_xy['Typical Appearance'] == 1].reset_index()\nIndeterminate_Appearance = complete_xy[complete_xy['Indeterminate Appearance'] == 1].reset_index()\nAtypical_Appearance = complete_xy[complete_xy['Atypical Appearance'] == 1].reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:20:35.276001Z","iopub.execute_input":"2021-06-14T06:20:35.276333Z","iopub.status.idle":"2021-06-14T06:20:35.295003Z","shell.execute_reply.started":"2021-06-14T06:20:35.276300Z","shell.execute_reply":"2021-06-14T06:20:35.293873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#      Typical Appearance character","metadata":{}},{"cell_type":"code","source":"#Typical_Appearance\n\n# Don't position = 200 why?!\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance.loc[pos,'boxes'])\n    link = Typical_Appearance['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Typical_Appearance', font='Serif', fontsize=20)\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:32:26.879010Z","iopub.execute_input":"2021-06-14T06:32:26.879311Z","iopub.status.idle":"2021-06-14T06:32:41.832463Z","shell.execute_reply.started":"2021-06-14T06:32:26.879286Z","shell.execute_reply":"2021-06-14T06:32:41.831254Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true,"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Indeterminate Appearance character","metadata":{}},{"cell_type":"code","source":"\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance.loc[pos,'boxes'])\n    link = Indeterminate_Appearance['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')\n    \n \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Indeterminate_Appearance', font='Serif', fontsize=20)\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:20:53.220085Z","iopub.execute_input":"2021-06-14T06:20:53.220351Z","iopub.status.idle":"2021-06-14T06:21:10.316796Z","shell.execute_reply.started":"2021-06-14T06:20:53.220325Z","shell.execute_reply":"2021-06-14T06:21:10.316167Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Atypical_Appearance character","metadata":{}},{"cell_type":"code","source":"\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Atypical_Appearance.loc[pos,'boxes'])\n    link = Atypical_Appearance['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')\n    \n \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Atypical_Appearance', font='Serif', fontsize=20)\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:21:10.320357Z","iopub.execute_input":"2021-06-14T06:21:10.320766Z","iopub.status.idle":"2021-06-14T06:21:29.424242Z","shell.execute_reply.started":"2021-06-14T06:21:10.320733Z","shell.execute_reply":"2021-06-14T06:21:29.423551Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **5. Photometric Interpretation of MONOCHROME1 &  MONOCHROME2**","metadata":{}},{"cell_type":"markdown","source":"**Typical_Appearance between MONOCHROME1 & 2**","metadata":{}},{"cell_type":"code","source":"Typical_Appearance1 = Typical_Appearance[Typical_Appearance['Photometric Interpretation']=='MONOCHROME1'].reset_index()\nTypical_Appearance2 = Typical_Appearance[Typical_Appearance['Photometric Interpretation']=='MONOCHROME2'].reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:21:29.426043Z","iopub.execute_input":"2021-06-14T06:21:29.426377Z","iopub.status.idle":"2021-06-14T06:21:29.436026Z","shell.execute_reply.started":"2021-06-14T06:21:29.426351Z","shell.execute_reply":"2021-06-14T06:21:29.435491Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Typical_Appearance1\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance1.loc[pos,'boxes'])\n    link = Typical_Appearance1['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Typical_Appearance with MONOCHROME1', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:21:29.436981Z","iopub.execute_input":"2021-06-14T06:21:29.437375Z","iopub.status.idle":"2021-06-14T06:21:44.640884Z","shell.execute_reply.started":"2021-06-14T06:21:29.437350Z","shell.execute_reply":"2021-06-14T06:21:44.640234Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Typical_Appearance2\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance2.loc[pos,'boxes'])\n    link = Typical_Appearance2['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Typical_Appearance with MONOCHROME2', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:21:44.641765Z","iopub.execute_input":"2021-06-14T06:21:44.642102Z","iopub.status.idle":"2021-06-14T06:22:02.640131Z","shell.execute_reply.started":"2021-06-14T06:21:44.642077Z","shell.execute_reply":"2021-06-14T06:22:02.639470Z"},"_kg_hide-output":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Indeterminate_Appearance between MONOCHROME1 & 2**","metadata":{}},{"cell_type":"code","source":"Indeterminate_Appearance1 = Indeterminate_Appearance[Indeterminate_Appearance['Photometric Interpretation']=='MONOCHROME1'].reset_index()\nIndeterminate_Appearance2 = Indeterminate_Appearance[Indeterminate_Appearance['Photometric Interpretation']=='MONOCHROME2'].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:22:02.641043Z","iopub.execute_input":"2021-06-14T06:22:02.641400Z","iopub.status.idle":"2021-06-14T06:22:02.649986Z","shell.execute_reply.started":"2021-06-14T06:22:02.641374Z","shell.execute_reply":"2021-06-14T06:22:02.649033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Indeterminate_Appearance1\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance1.loc[pos,'boxes'])\n    link = Indeterminate_Appearance1['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Indeterminate_Appearance with MONOCHROME1', font='Serif', fontsize=15)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:22:02.651006Z","iopub.execute_input":"2021-06-14T06:22:02.651428Z","iopub.status.idle":"2021-06-14T06:22:18.687464Z","shell.execute_reply.started":"2021-06-14T06:22:02.651400Z","shell.execute_reply":"2021-06-14T06:22:18.686313Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Indeterminate_Appearance2\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance2.loc[pos,'boxes'])\n    link = Indeterminate_Appearance2['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Indeterminate_Appearance with MONOCHROME2', font='Serif', fontsize=15)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:22:18.689087Z","iopub.execute_input":"2021-06-14T06:22:18.689462Z","iopub.status.idle":"2021-06-14T06:22:36.059823Z","shell.execute_reply.started":"2021-06-14T06:22:18.689427Z","shell.execute_reply":"2021-06-14T06:22:36.059080Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Atypical_Appearance between MONOCHROME1 & 2**","metadata":{}},{"cell_type":"code","source":"Atypical_Appearance1 = Atypical_Appearance[Atypical_Appearance['Photometric Interpretation']=='MONOCHROME1'].reset_index()\nAtypical_Appearance2 = Atypical_Appearance[Atypical_Appearance['Photometric Interpretation']=='MONOCHROME2'].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:22:36.060965Z","iopub.execute_input":"2021-06-14T06:22:36.061405Z","iopub.status.idle":"2021-06-14T06:22:36.068991Z","shell.execute_reply.started":"2021-06-14T06:22:36.061378Z","shell.execute_reply":"2021-06-14T06:22:36.068135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Atypical_Appearance1\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Atypical_Appearance1.loc[pos,'boxes'])\n    link = Atypical_Appearance1['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Atypical_Appearance with MONOCHROME1', font='Serif', fontsize=15)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:22:36.070126Z","iopub.execute_input":"2021-06-14T06:22:36.070384Z","iopub.status.idle":"2021-06-14T06:22:52.035196Z","shell.execute_reply.started":"2021-06-14T06:22:36.070360Z","shell.execute_reply":"2021-06-14T06:22:52.034291Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Atypical_Appearance2\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Atypical_Appearance2.loc[pos,'boxes'])\n    link = Atypical_Appearance2['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,i].set_title('Atypical_Appearance with MONOCHROME2', font='Serif', fontsize=15)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true,"outputs_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:22:52.036332Z","iopub.execute_input":"2021-06-14T06:22:52.036605Z","iopub.status.idle":"2021-06-14T06:23:06.304407Z","shell.execute_reply.started":"2021-06-14T06:22:52.036579Z","shell.execute_reply":"2021-06-14T06:23:06.303784Z"},"_kg_hide-output":true,"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 6. Modality\n\nSeperation between PA film and AP file.\n\n**Defind: **\n\nModality_CR = PA film\n\nModelity_DX = AP film\n\nIs it correct? \n\n![](https://www.criticalcarepractitioner.co.uk/wp-content/uploads/2012/05/ap_vs_pa_opt.jpg)\n\ncredit: https://www.criticalcarepractitioner.co.uk/wp-content/uploads/2012/05/ap_vs_pa_opt.jpg","metadata":{}},{"cell_type":"markdown","source":"* # Negative for Pneumonia","metadata":{}},{"cell_type":"code","source":"Negative_Pneumonia = complete_data[complete_data['Negative for Pneumonia']==1]\nNegative_Pneumonia1_cr = Negative_Pneumonia[(Negative_Pneumonia['Photometric Interpretation']=='MONOCHROME1') &\n                                            (Negative_Pneumonia['Modality'] == 'CR')].reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:46:24.311974Z","iopub.execute_input":"2021-06-14T06:46:24.312299Z","iopub.status.idle":"2021-06-14T06:46:24.323500Z","shell.execute_reply.started":"2021-06-14T06:46:24.312271Z","shell.execute_reply":"2021-06-14T06:46:24.322400Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Negative_Pneumonia1_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(2,2, figsize=(25,20))\n\nfor pos in range(4):\n    \n    link = Negative_Pneumonia1_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 1:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Negative_Pneumonia with MONOCHROME1 & Modality:CR', font='Serif', fontsize=20)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:51:46.035545Z","iopub.execute_input":"2021-06-14T06:51:46.035964Z","iopub.status.idle":"2021-06-14T06:51:50.779459Z","shell.execute_reply.started":"2021-06-14T06:51:46.035930Z","shell.execute_reply":"2021-06-14T06:51:50.778373Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Negative_Pneumonia = complete_data[complete_data['Negative for Pneumonia']==1]\nNegative_Pneumonia1_dx = Negative_Pneumonia[(Negative_Pneumonia['Photometric Interpretation']=='MONOCHROME1') &\n                                            (Negative_Pneumonia['Modality'] == 'DX')].reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:53:48.570547Z","iopub.execute_input":"2021-06-14T06:53:48.570875Z","iopub.status.idle":"2021-06-14T06:53:48.580891Z","shell.execute_reply.started":"2021-06-14T06:53:48.570848Z","shell.execute_reply":"2021-06-14T06:53:48.579969Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Negative_Pneumonia1_dx\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(2,2, figsize=(25,20))\n\nfor pos in range(4):\n    \n    link = Negative_Pneumonia1_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 1:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Negative_Pneumonia with MONOCHROME1 & Modality:DX', font='Serif', fontsize=20)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:53:57.735252Z","iopub.execute_input":"2021-06-14T06:53:57.735749Z","iopub.status.idle":"2021-06-14T06:54:03.470131Z","shell.execute_reply.started":"2021-06-14T06:53:57.735718Z","shell.execute_reply":"2021-06-14T06:54:03.469558Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Negative_Pneumonia = complete_data[complete_data['Negative for Pneumonia']==1]\nNegative_Pneumonia2_cr = Negative_Pneumonia[(Negative_Pneumonia['Photometric Interpretation']=='MONOCHROME2') &\n                                            (Negative_Pneumonia['Modality'] == 'CR')].reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:54:55.419025Z","iopub.execute_input":"2021-06-14T06:54:55.419600Z","iopub.status.idle":"2021-06-14T06:54:55.429703Z","shell.execute_reply.started":"2021-06-14T06:54:55.419539Z","shell.execute_reply":"2021-06-14T06:54:55.428599Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Negative_Pneumonia2_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(2,2, figsize=(25,20))\n\nfor pos in range(4):\n    \n    link = Negative_Pneumonia2_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 1:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Negative_Pneumonia with MONOCHROME2 & Modality:CR', font='Serif', fontsize=20)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:55:45.975709Z","iopub.execute_input":"2021-06-14T06:55:45.976051Z","iopub.status.idle":"2021-06-14T06:55:49.112787Z","shell.execute_reply.started":"2021-06-14T06:55:45.976017Z","shell.execute_reply":"2021-06-14T06:55:49.111737Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Negative_Pneumonia = complete_data[complete_data['Negative for Pneumonia']==1]\nNegative_Pneumonia2_dx = Negative_Pneumonia[(Negative_Pneumonia['Photometric Interpretation']=='MONOCHROME2') &\n                                            (Negative_Pneumonia['Modality'] == 'DX')].reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:56:36.076954Z","iopub.execute_input":"2021-06-14T06:56:36.077263Z","iopub.status.idle":"2021-06-14T06:56:36.090930Z","shell.execute_reply.started":"2021-06-14T06:56:36.077235Z","shell.execute_reply":"2021-06-14T06:56:36.089970Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Negative_Pneumonia2_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(2,2, figsize=(25,20))\n\nfor pos in range(4):\n    \n    link = Negative_Pneumonia2_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 1:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Negative_Pneumonia with MONOCHROME2 & Modality:DX', font='Serif', fontsize=20)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T06:56:50.061657Z","iopub.execute_input":"2021-06-14T06:56:50.062137Z","iopub.status.idle":"2021-06-14T06:56:57.062226Z","shell.execute_reply.started":"2021-06-14T06:56:50.062108Z","shell.execute_reply":"2021-06-14T06:56:57.061140Z"},"_kg_hide-input":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*    # Typical_Appearance","metadata":{}},{"cell_type":"code","source":"# CR & DX\n\nTypical_Appearance1_cr = Typical_Appearance[(Typical_Appearance['Photometric Interpretation']=='MONOCHROME1') &\n                                            (Typical_Appearance['Modality'] == 'CR')].reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:23:06.305318Z","iopub.execute_input":"2021-06-14T06:23:06.305678Z","iopub.status.idle":"2021-06-14T06:23:06.311979Z","shell.execute_reply.started":"2021-06-14T06:23:06.305652Z","shell.execute_reply":"2021-06-14T06:23:06.311452Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Typical_Appearance1_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance1_cr.loc[pos,'boxes'])\n    link = Typical_Appearance1_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Typical_Appearance with MONOCHROME1 & Modality:CR', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:35:46.489301Z","iopub.execute_input":"2021-06-14T06:35:46.489735Z","iopub.status.idle":"2021-06-14T06:35:56.122645Z","shell.execute_reply.started":"2021-06-14T06:35:46.489698Z","shell.execute_reply":"2021-06-14T06:35:56.121484Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Typical_Appearance1_dx = Typical_Appearance[(Typical_Appearance['Photometric Interpretation']=='MONOCHROME1') &\n                                            (Typical_Appearance['Modality'] == 'DX')].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:23:24.061321Z","iopub.execute_input":"2021-06-14T06:23:24.061597Z","iopub.status.idle":"2021-06-14T06:23:24.069026Z","shell.execute_reply.started":"2021-06-14T06:23:24.061571Z","shell.execute_reply":"2021-06-14T06:23:24.068433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Typical_Appearance1_dx\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance1_dx.loc[pos,'boxes'])\n    link = Typical_Appearance1_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Typical_Appearance with MONOCHROME1 & Modality:DX', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:36:06.104019Z","iopub.execute_input":"2021-06-14T06:36:06.104416Z","iopub.status.idle":"2021-06-14T06:36:14.123780Z","shell.execute_reply.started":"2021-06-14T06:36:06.104384Z","shell.execute_reply":"2021-06-14T06:36:14.122711Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Typical_Appearance2_cr = Typical_Appearance[(Typical_Appearance['Photometric Interpretation']=='MONOCHROME2') &\n                                            (Typical_Appearance['Modality'] == 'CR')].reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:23:37.610799Z","iopub.execute_input":"2021-06-14T06:23:37.611242Z","iopub.status.idle":"2021-06-14T06:23:37.620877Z","shell.execute_reply.started":"2021-06-14T06:23:37.611210Z","shell.execute_reply":"2021-06-14T06:23:37.620067Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Typical_Appearance2_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance2_cr.loc[pos,'boxes'])\n    link = Typical_Appearance2_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Typical_Appearance with MONOCHROME2 & Modality:CR', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:36:19.180302Z","iopub.execute_input":"2021-06-14T06:36:19.180685Z","iopub.status.idle":"2021-06-14T06:36:27.936174Z","shell.execute_reply.started":"2021-06-14T06:36:19.180650Z","shell.execute_reply":"2021-06-14T06:36:27.935184Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Typical_Appearance2_dx = Typical_Appearance[(Typical_Appearance['Photometric Interpretation']=='MONOCHROME2') &\n                                            (Typical_Appearance['Modality'] == 'DX')].reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:23:53.432461Z","iopub.execute_input":"2021-06-14T06:23:53.432950Z","iopub.status.idle":"2021-06-14T06:23:53.441493Z","shell.execute_reply.started":"2021-06-14T06:23:53.432914Z","shell.execute_reply":"2021-06-14T06:23:53.440612Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Typical_Appearance2_dx\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Typical_Appearance2_dx.loc[pos,'boxes'])\n    link = Typical_Appearance2_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='g', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Typical_Appearance with MONOCHROME2 & Modality:DX', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:36:34.855744Z","iopub.execute_input":"2021-06-14T06:36:34.856061Z","iopub.status.idle":"2021-06-14T06:36:45.909233Z","shell.execute_reply.started":"2021-06-14T06:36:34.856035Z","shell.execute_reply":"2021-06-14T06:36:45.908533Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*    # Indeterminate_Appearance \n","metadata":{}},{"cell_type":"code","source":"# CR & DX\nIndeterminate_Appearance1_cr = Indeterminate_Appearance[(Indeterminate_Appearance['Photometric Interpretation']=='MONOCHROME1') &\n                                                        (Indeterminate_Appearance['Modality'] == 'CR')].reset_index()\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:24:09.299701Z","iopub.execute_input":"2021-06-14T06:24:09.299992Z","iopub.status.idle":"2021-06-14T06:24:09.307892Z","shell.execute_reply.started":"2021-06-14T06:24:09.299963Z","shell.execute_reply":"2021-06-14T06:24:09.306712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Indeterminate_Appearance1_cr \n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance1_cr.loc[pos,'boxes'])\n    link = Indeterminate_Appearance1_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Indeterminate_Appearance with MONOCHROME1 & Modality:CR', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:36:51.437428Z","iopub.execute_input":"2021-06-14T06:36:51.437903Z","iopub.status.idle":"2021-06-14T06:37:01.600210Z","shell.execute_reply.started":"2021-06-14T06:36:51.437874Z","shell.execute_reply":"2021-06-14T06:37:01.599634Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Indeterminate_Appearance1_dx = Indeterminate_Appearance[(Indeterminate_Appearance['Photometric Interpretation']=='MONOCHROME1') &\n                                                        (Indeterminate_Appearance['Modality'] == 'DX')].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:24:27.570787Z","iopub.execute_input":"2021-06-14T06:24:27.571111Z","iopub.status.idle":"2021-06-14T06:24:27.576999Z","shell.execute_reply.started":"2021-06-14T06:24:27.571078Z","shell.execute_reply":"2021-06-14T06:24:27.576405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Indeterminate_Appearance1_dx \n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance1_dx.loc[pos,'boxes'])\n    link = Indeterminate_Appearance1_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Indeterminate_Appearance with MONOCHROME1 & Modality:DX', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:37:06.531794Z","iopub.execute_input":"2021-06-14T06:37:06.532264Z","iopub.status.idle":"2021-06-14T06:37:14.588822Z","shell.execute_reply.started":"2021-06-14T06:37:06.532235Z","shell.execute_reply":"2021-06-14T06:37:14.587785Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# CR & DX\nIndeterminate_Appearance2_cr = Indeterminate_Appearance[(Indeterminate_Appearance['Photometric Interpretation']=='MONOCHROME2') &\n                                                        (Indeterminate_Appearance['Modality'] == 'CR')].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:24:42.313009Z","iopub.execute_input":"2021-06-14T06:24:42.313301Z","iopub.status.idle":"2021-06-14T06:24:42.320795Z","shell.execute_reply.started":"2021-06-14T06:24:42.313271Z","shell.execute_reply":"2021-06-14T06:24:42.319889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Indeterminate_Appearance2_cr \n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance2_cr.loc[pos,'boxes'])\n    link = Indeterminate_Appearance2_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Indeterminate_Appearance with MONOCHROME2 & Modality:CR', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:37:20.661548Z","iopub.execute_input":"2021-06-14T06:37:20.661915Z","iopub.status.idle":"2021-06-14T06:37:28.676009Z","shell.execute_reply.started":"2021-06-14T06:37:20.661868Z","shell.execute_reply":"2021-06-14T06:37:28.675340Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Indeterminate_Appearance2_dx = Indeterminate_Appearance[(Indeterminate_Appearance['Photometric Interpretation']=='MONOCHROME2') &\n                                                        (Indeterminate_Appearance['Modality'] == 'DX')].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:24:55.673546Z","iopub.execute_input":"2021-06-14T06:24:55.673811Z","iopub.status.idle":"2021-06-14T06:24:55.681335Z","shell.execute_reply.started":"2021-06-14T06:24:55.673785Z","shell.execute_reply":"2021-06-14T06:24:55.680369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Indeterminate_Appearance2_dx\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,3, figsize=(25,20))\n\nfor pos in range(9):\n    \n    boxes = ast.literal_eval(Indeterminate_Appearance2_dx.loc[pos,'boxes'])\n    link = Indeterminate_Appearance2_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='b', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(img,cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Indeterminate_Appearance with MONOCHROME2 & Modality:DX', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:24:55.682466Z","iopub.execute_input":"2021-06-14T06:24:55.682812Z","iopub.status.idle":"2021-06-14T06:25:10.842626Z","shell.execute_reply.started":"2021-06-14T06:24:55.682785Z","shell.execute_reply":"2021-06-14T06:25:10.841666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*    # Atypical_Appearance","metadata":{}},{"cell_type":"code","source":"# CR & DX\nAtypical_Appearance1_cr = Atypical_Appearance[(Atypical_Appearance['Photometric Interpretation']=='MONOCHROME1')&\n                                             (Atypical_Appearance['Modality'] == 'CR')].reset_index()\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:25:10.843946Z","iopub.execute_input":"2021-06-14T06:25:10.844214Z","iopub.status.idle":"2021-06-14T06:25:10.850790Z","shell.execute_reply.started":"2021-06-14T06:25:10.844188Z","shell.execute_reply":"2021-06-14T06:25:10.849978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Atypical_Appearance1_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,2, figsize=(25,20))\n\nfor pos in range(6):\n    \n    boxes = ast.literal_eval(Atypical_Appearance1_cr.loc[pos,'boxes'])\n    link = Atypical_Appearance1_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Atypical_Appearance with MONOCHROME1 & Modality:CR', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:37:36.220338Z","iopub.execute_input":"2021-06-14T06:37:36.220926Z","iopub.status.idle":"2021-06-14T06:37:42.984351Z","shell.execute_reply.started":"2021-06-14T06:37:36.220857Z","shell.execute_reply":"2021-06-14T06:37:42.983598Z"},"jupyter":{"source_hidden":true,"outputs_hidden":true},"collapsed":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Atypical_Appearance1_dx = Atypical_Appearance[(Atypical_Appearance['Photometric Interpretation']=='MONOCHROME1')&\n                                             (Atypical_Appearance['Modality'] == 'DX')].reset_index()\n","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:25:23.106357Z","iopub.execute_input":"2021-06-14T06:25:23.106621Z","iopub.status.idle":"2021-06-14T06:25:23.112315Z","shell.execute_reply.started":"2021-06-14T06:25:23.106595Z","shell.execute_reply":"2021-06-14T06:25:23.111688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Atypical_Appearance1_dx\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,2, figsize=(25,20))\n\nfor pos in range(6):\n    \n    boxes = ast.literal_eval(Atypical_Appearance1_dx.loc[pos,'boxes'])\n    link = Atypical_Appearance1_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Atypical_Appearance with MONOCHROME1 & Modality:DX', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:37:55.608777Z","iopub.execute_input":"2021-06-14T06:37:55.609304Z","iopub.status.idle":"2021-06-14T06:38:01.094129Z","shell.execute_reply.started":"2021-06-14T06:37:55.609258Z","shell.execute_reply":"2021-06-14T06:38:01.093116Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Atypical_Appearance2_cr = Atypical_Appearance[(Atypical_Appearance['Photometric Interpretation']=='MONOCHROME2')&\n                                             (Atypical_Appearance['Modality'] == 'CR')].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:25:31.860858Z","iopub.execute_input":"2021-06-14T06:25:31.861151Z","iopub.status.idle":"2021-06-14T06:25:31.867291Z","shell.execute_reply.started":"2021-06-14T06:25:31.861125Z","shell.execute_reply":"2021-06-14T06:25:31.866532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Atypical_Appearance2_cr\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,2, figsize=(25,20))\n\nfor pos in range(6):\n    \n    boxes = ast.literal_eval(Atypical_Appearance2_cr.loc[pos,'boxes'])\n    link = Atypical_Appearance2_cr['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Atypical_Appearance with MONOCHROME2 & Modality:CR', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:38:07.467045Z","iopub.execute_input":"2021-06-14T06:38:07.467443Z","iopub.status.idle":"2021-06-14T06:38:14.155207Z","shell.execute_reply.started":"2021-06-14T06:38:07.467410Z","shell.execute_reply":"2021-06-14T06:38:14.154266Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Atypical_Appearance2_dx = Atypical_Appearance[(Atypical_Appearance['Photometric Interpretation']=='MONOCHROME2')&\n                                             (Atypical_Appearance['Modality'] == 'DX')].reset_index()","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:25:41.434303Z","iopub.execute_input":"2021-06-14T06:25:41.434840Z","iopub.status.idle":"2021-06-14T06:25:41.442775Z","shell.execute_reply.started":"2021-06-14T06:25:41.434802Z","shell.execute_reply":"2021-06-14T06:25:41.441789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Atypical_Appearance2_dx\n\n\ni = 0\nj = 0\n\nfig, ax = plt.subplots(3,2, figsize=(25,20))\n\nfor pos in range(6):\n    \n    boxes = ast.literal_eval(Atypical_Appearance2_dx.loc[pos,'boxes'])\n    link = Atypical_Appearance2_dx['path'].iloc[pos]\n    ds_pos = [0 for p in range(pos+1)]\n    ds_pos[pos] = pydicom.dcmread(link).pixel_array\n    #img = exposure.equalize_hist(ds_pos[pos])\n\n    for box in boxes:\n        p = matplotlib.patches.Rectangle((box['x'], box['y']),\n                                      box['width'], box['height'],\n                                      ec='r', fc='none', lw=1)\n        ax[i,j].add_patch(p)\n    ax[i,j].imshow(ds_pos[pos],cmap='gray')    \n    \n    i +=1      \n    if i > 2:\n        i = 0\n        j +=1\n    ax[0,0].set_title('Atypical_Appearance with MONOCHROME2 & Modality:DX', font='Serif', fontsize=20)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-14T06:38:19.653082Z","iopub.execute_input":"2021-06-14T06:38:19.653458Z","iopub.status.idle":"2021-06-14T06:38:25.604975Z","shell.execute_reply.started":"2021-06-14T06:38:19.653423Z","shell.execute_reply":"2021-06-14T06:38:25.604075Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Histrogram **","metadata":{}},{"cell_type":"markdown","source":"* **Reval view**","metadata":{}},{"cell_type":"code","source":"#Histogram  '.ravel' returns a view of the original array\nlabel_appearance = list(train_study_level.columns)[1:5]\nrow_img = 2\ncol_img = len(label_appearance)\n\nc= 0\ncolor = 'gray'\nds_pos = [0 for p in range(row_img)]\n\nfig,ax = plt.subplots(row_img,col_img, figsize=(20,row_img*4))\n\nfor i in label_appearance:\n    for r in range(row_img):\n        link = train_image_level[train_image_level[i] == 1]['path'].iloc[r]\n        ds_pos[r] = pydicom.dcmread(link).pixel_array\n        \n        #ax[r,c].hist(ds_pos[r].flatten(), bins=50)\n        ax[r,c].hist(ds_pos[r].ravel(),256)\n        \n        plt.xlabel('')\n        plt.ylabel(\"Frequency\")\n      \n    ax[0,c].set_title(i, font='Serif', fontsize=20)\n    c +=1","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:25:51.183072Z","iopub.execute_input":"2021-06-14T06:25:51.183427Z","iopub.status.idle":"2021-06-14T06:25:56.915169Z","shell.execute_reply.started":"2021-06-14T06:25:51.183400Z","shell.execute_reply":"2021-06-14T06:25:56.914574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Flatten view**","metadata":{}},{"cell_type":"code","source":"#histogram  '.flatten' \nlabel_appearance = list(train_study_level.columns)[1:5]\nrow_img = 2\ncol_img = len(label_appearance)\n\nc= 0\ncolor = 'gray'\nds_pos = [0 for p in range(row_img)]\n\nfig,ax = plt.subplots(row_img,col_img, figsize=(20,row_img*4))\n\nfor i in label_appearance:\n    for r in range(row_img):\n        link = train_image_level[train_image_level[i] == 1]['path'].iloc[r]\n        ds_pos[r] = pydicom.dcmread(link).pixel_array\n        \n        ax[r,c].hist(ds_pos[r].flatten(), bins=50)      \n        plt.xlabel('')\n        plt.ylabel(\"Frequency\")\n      \n    ax[0,c].set_title(i, font='Serif', fontsize=20)\n    c +=1","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2021-06-14T06:25:56.916046Z","iopub.execute_input":"2021-06-14T06:25:56.916364Z","iopub.status.idle":"2021-06-14T06:25:59.828624Z","shell.execute_reply.started":"2021-06-14T06:25:56.916339Z","shell.execute_reply":"2021-06-14T06:25:59.827655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Work in process**","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}