{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-29T18:59:11.429315Z","iopub.execute_input":"2022-12-29T18:59:11.430375Z","iopub.status.idle":"2022-12-29T18:59:11.43599Z","shell.execute_reply.started":"2022-12-29T18:59:11.430336Z","shell.execute_reply":"2022-12-29T18:59:11.434752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install -qU python-gdcm pydicom pylibjpeg","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:11.797148Z","iopub.execute_input":"2022-12-29T18:59:11.797544Z","iopub.status.idle":"2022-12-29T18:59:11.802027Z","shell.execute_reply.started":"2022-12-29T18:59:11.797508Z","shell.execute_reply":"2022-12-29T18:59:11.800945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport glob\n#import gdcm\nimport pydicom\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nfrom tqdm.notebook import tqdm\nfrom joblib import Parallel, delayed","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:12.025592Z","iopub.execute_input":"2022-12-29T18:59:12.025964Z","iopub.status.idle":"2022-12-29T18:59:12.031469Z","shell.execute_reply.started":"2022-12-29T18:59:12.025934Z","shell.execute_reply":"2022-12-29T18:59:12.030447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *\n","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:13.325109Z","iopub.execute_input":"2022-12-29T18:59:13.326226Z","iopub.status.idle":"2022-12-29T18:59:13.332534Z","shell.execute_reply.started":"2022-12-29T18:59:13.326178Z","shell.execute_reply":"2022-12-29T18:59:13.331434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_csv = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ntest_csv = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/test.csv')\n\ntest_url='/kaggle/input/rsna-breast-cancer-detection/test_images/'\n# # train_url='/kaggle/input/rsna-breast-cancer-detection/train_images/'","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:13.657152Z","iopub.execute_input":"2022-12-29T18:59:13.657527Z","iopub.status.idle":"2022-12-29T18:59:13.669476Z","shell.execute_reply.started":"2022-12-29T18:59:13.657498Z","shell.execute_reply":"2022-12-29T18:59:13.668197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_ = []\nfor i in range(len(test_csv)):\n    path = test_url+(test_csv.iloc[i].patient_id.astype(str))+'/'+(test_csv.iloc[i].image_id.astype(str))+'.dcm'\n    path_.append(path)","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:13.853014Z","iopub.execute_input":"2022-12-29T18:59:13.854034Z","iopub.status.idle":"2022-12-29T18:59:13.862159Z","shell.execute_reply.started":"2022-12-29T18:59:13.853971Z","shell.execute_reply":"2022-12-29T18:59:13.861061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_csv['path_url']=path_\n","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:14.564787Z","iopub.execute_input":"2022-12-29T18:59:14.565888Z","iopub.status.idle":"2022-12-29T18:59:14.571491Z","shell.execute_reply.started":"2022-12-29T18:59:14.565846Z","shell.execute_reply":"2022-12-29T18:59:14.570413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"uuu='/kaggle/tmp/'\npath_converedImages = []\nfor i in range(len(test_csv)):\n    \n    x=test_csv.iloc[i]['path_url']\n    dicom = pydicom.dcmread(x)\n    #dicom = pydicom.read_file(x)\n    img = dicom.pixel_array\n    \n#     img = (img - img.min()) / (img.max() - img.min())\n#     if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n#         img = 1 - img\n        \n    width = 256\n    height = 256\n    dim = (width, height)\n    # resize image\n    resized = cv2.resize(img, dim )\n    path = uuu+(test_csv.iloc[i].image_id.astype(str))+'.png'\n    cv2.imwrite(path,resized)\n    path_converedImages.append(path)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:15.070772Z","iopub.execute_input":"2022-12-29T18:59:15.071205Z","iopub.status.idle":"2022-12-29T18:59:16.780636Z","shell.execute_reply.started":"2022-12-29T18:59:15.07117Z","shell.execute_reply":"2022-12-29T18:59:16.779468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_converedImages","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:59:16.782597Z","iopub.execute_input":"2022-12-29T18:59:16.782946Z","iopub.status.idle":"2022-12-29T18:59:16.789504Z","shell.execute_reply.started":"2022-12-29T18:59:16.782915Z","shell.execute_reply":"2022-12-29T18:59:16.788467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_file = '/kaggle/input/rsna-breast-cancer-detection/test.csv'\ntest_df = pd.read_csv(csv_file)\ntest_df.loc[:, 'cancer'] = np.random.uniform(0,1,len(test_df)) #  dummy probability values\nsubmit_df = test_df[['prediction_id', 'cancer']]\nsubmit_df = submit_df.groupby('prediction_id').mean()  #dummy aggregation method\nsubmit_df = submit_df.sort_index()\nsubmit_df.to_csv('submission.csv',index=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-29T18:20:48.307729Z","iopub.execute_input":"2022-12-29T18:20:48.30812Z","iopub.status.idle":"2022-12-29T18:20:48.334295Z","shell.execute_reply.started":"2022-12-29T18:20:48.30809Z","shell.execute_reply":"2022-12-29T18:20:48.333159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_converedImages","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}