{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        os.path.join(dirname, filename)\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":"2023-08-30T20:28:31.663066Z","iopub.execute_input":"2023-08-30T20:28:31.663433Z","iopub.status.idle":"2023-08-30T20:28:51.462138Z","shell.execute_reply.started":"2023-08-30T20:28:31.663401Z","shell.execute_reply":"2023-08-30T20:28:51.461284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data=\"/kaggle/input/prostate-cancer-grade-assessment/train.csv\"","metadata":{"execution":{"iopub.status.busy":"2023-08-30T20:28:51.464006Z","iopub.execute_input":"2023-08-30T20:28:51.464997Z","iopub.status.idle":"2023-08-30T20:28:51.470044Z","shell.execute_reply.started":"2023-08-30T20:28:51.46496Z","shell.execute_reply":"2023-08-30T20:28:51.468897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##dataframe\ndf=pd.read_csv(training_data)\n\ndf","metadata":{"execution":{"iopub.status.busy":"2023-08-30T20:28:51.471487Z","iopub.execute_input":"2023-08-30T20:28:51.471945Z","iopub.status.idle":"2023-08-30T20:28:51.538626Z","shell.execute_reply.started":"2023-08-30T20:28:51.471907Z","shell.execute_reply":"2023-08-30T20:28:51.537663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n##all the unique isup grades\ngrades=df['isup_grade'].unique()\n\nresult=df.groupby('isup_grade').head(2)\n\nimage_ids=result['image_id']","metadata":{"execution":{"iopub.status.busy":"2023-08-30T20:28:51.541346Z","iopub.execute_input":"2023-08-30T20:28:51.541941Z","iopub.status.idle":"2023-08-30T20:28:51.55418Z","shell.execute_reply.started":"2023-08-30T20:28:51.54191Z","shell.execute_reply":"2023-08-30T20:28:51.553058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\n\n# test_img=image_ids[0]\n\n# test_img\n\n# file_path=f\"/kaggle/input/prostate-cancer-grade-assessment/train_images/{test_img}.tiff\"\nsubset=[]\n\nfor ids in image_ids:\n    file_path=f\"/kaggle/input/prostate-cancer-grade-assessment/train_images/{ids}.tiff\"\n    img_arr=cv2.imread(file_path)\n    subset.append(img_arr)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-30T20:28:51.5555Z","iopub.execute_input":"2023-08-30T20:28:51.556018Z","iopub.status.idle":"2023-08-30T20:30:01.732424Z","shell.execute_reply.started":"2023-08-30T20:28:51.555984Z","shell.execute_reply":"2023-08-30T20:30:01.731341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subset=np.array(subset)\n\n\n##subset shape=(12,0)\n\n##one image example (x*y*3)\nimg=subset[2]\n\n\n##images are ready \n\n#we need to tile the images, ask Dr Salah for clarification\n\nimg.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-30T21:40:57.673196Z","iopub.execute_input":"2023-08-30T21:40:57.674106Z","iopub.status.idle":"2023-08-30T21:40:57.681534Z","shell.execute_reply.started":"2023-08-30T21:40:57.674067Z","shell.execute_reply":"2023-08-30T21:40:57.680155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##splitting the images into 16 tiles\n\n\ndef split_image(img):\n    shape = img.shape\n    row, col = shape[0], shape[1]\n    \n    tiles = []\n    tile_size = 256\n    \n    for i in range(0, row, tile_size):\n        for j in range(0, col, tile_size):\n            tile=img[i:i+tile_size, j:j+tile_size]\n            tiles.append(tile)\n    \n    ##getting the 16 tiles of 256 by 256\n    return np.array(tiles)[0:16]\n            \n            ","metadata":{"execution":{"iopub.status.busy":"2023-08-30T21:40:59.342633Z","iopub.execute_input":"2023-08-30T21:40:59.343034Z","iopub.status.idle":"2023-08-30T21:40:59.350929Z","shell.execute_reply.started":"2023-08-30T21:40:59.343003Z","shell.execute_reply":"2023-08-30T21:40:59.349303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tiles=split_image(img)\n\n\n\ndef combine_tiles(tiles):\n    tiles=tiles.reshape(4,4,256,256,3)\n    \n    combined_image=tiles.transpose(0, 2, 1, 3, 4).reshape(4 * 256, 4 * 256, 3)\n    \n    return combined_image\n        \n\nimage=combine_tiles(tiles)\n\n##time to normalize the iamge\ndef normalize_image(image):\n    normalized_image=np.dot(image, [0.2989, 0.5870, 0.1140])\n    return normalized_image\n\nnormalized_image=normalize_image(image)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-08-30T22:03:09.233386Z","iopub.execute_input":"2023-08-30T22:03:09.233878Z","iopub.status.idle":"2023-08-30T22:03:09.458051Z","shell.execute_reply.started":"2023-08-30T22:03:09.233837Z","shell.execute_reply":"2023-08-30T22:03:09.456651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}],"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"}}