{"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":"import pandas as pd\ntrain=pd.read_csv('/kaggle/input/prostate-cancer-grade-assessment/train.csv')\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-26T19:31:38.52485Z","iopub.execute_input":"2021-09-26T19:31:38.525152Z","iopub.status.idle":"2021-09-26T19:31:38.590581Z","shell.execute_reply.started":"2021-09-26T19:31:38.525096Z","shell.execute_reply":"2021-09-26T19:31:38.589697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Location of training labels\ntrain_labels = pd.read_csv('/kaggle/input/prostate-cancer-grade-assessment/train.csv').set_index('image_id')\ntrain_labels.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-26T19:53:20.300552Z","iopub.execute_input":"2021-09-26T19:53:20.301456Z","iopub.status.idle":"2021-09-26T19:53:20.32978Z","shell.execute_reply.started":"2021-09-26T19:53:20.301415Z","shell.execute_reply":"2021-09-26T19:53:20.329179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Location of the training images\ndata_dir = '/kaggle/input/prostate-cancer-grade-assessment/train_images'\nmask_dir = '/kaggle/input/prostate-cancer-grade-assessment/train_label_masks'","metadata":{"execution":{"iopub.status.busy":"2021-09-26T19:31:47.089574Z","iopub.execute_input":"2021-09-26T19:31:47.089865Z","iopub.status.idle":"2021-09-26T19:31:47.093912Z","shell.execute_reply.started":"2021-09-26T19:31:47.089836Z","shell.execute_reply":"2021-09-26T19:31:47.093211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def slide_details(slide, show_thumbnail=True, max_size=(600,400)):\n    \"\"\"Print some basic information about a slide\"\"\"\n    # Generate a small image thumbnail\n    if show_thumbnail:\n        display(slide.get_thumbnail(size=max_size))\n    # Here we compute the \"pixel spacing\": the physical size of a pixel in the image.\n    # OpenSlide gives the resolution in centimeters so we convert this to microns.\n    spacing = 1 / (float(slide.properties['tiff.XResolution']) / 10000)\n    downsamples = slide.level_downsamples\n    slide_dim = slide.dimensions\n    return spacing, downsamples, slide_dim","metadata":{"execution":{"iopub.status.busy":"2021-09-26T20:01:24.736697Z","iopub.execute_input":"2021-09-26T20:01:24.737613Z","iopub.status.idle":"2021-09-26T20:01:24.743885Z","shell.execute_reply.started":"2021-09-26T20:01:24.73757Z","shell.execute_reply":"2021-09-26T20:01:24.74321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im_id = [name for name in train['image_id']]","metadata":{"execution":{"iopub.status.busy":"2021-09-26T19:31:54.033982Z","iopub.execute_input":"2021-09-26T19:31:54.034551Z","iopub.status.idle":"2021-09-26T19:31:54.043207Z","shell.execute_reply.started":"2021-09-26T19:31:54.034517Z","shell.execute_reply":"2021-09-26T19:31:54.04215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import openslide\nimport os\n\nexample_slides = im_id\nimg_id = []\npixel_spacing = []\ndownsamples = []\ngleason = []\nslide_dimension = []\n\nfor case_id in example_slides:\n    biopsy = openslide.OpenSlide(os.path.join(data_dir, f'{case_id}.tiff'))\n    img_id.append(case_id)\n    pix_spg, downsamp, sld_dim = slide_details(biopsy, show_thumbnail=False)\n    pixel_spacing.append(pix_spg)\n    downsamples.append(downsamp)\n    slide_dimension.append(sld_dim)\n    gleason.append(train_labels.loc[case_id, 'gleason_score'])\n    biopsy.close()\n    \n#data = {'img_id':img_id,'pixel_spacing': pixel_spacing, 'downsamples': downsamples}    \ndata = {'img_id':img_id,'pixel_spacing': pixel_spacing, 'downsamples': downsamples, 'slide_dimension': slide_dimension, 'gleason': gleason}    \ndf_slide_details = pd.DataFrame(data)   ","metadata":{"execution":{"iopub.status.busy":"2021-09-26T20:01:32.684845Z","iopub.execute_input":"2021-09-26T20:01:32.685388Z","iopub.status.idle":"2021-09-26T20:01:34.143182Z","shell.execute_reply.started":"2021-09-26T20:01:32.685321Z","shell.execute_reply":"2021-09-26T20:01:34.14217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_slide_details.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-26T20:01:38.091558Z","iopub.execute_input":"2021-09-26T20:01:38.0919Z","iopub.status.idle":"2021-09-26T20:01:38.107996Z","shell.execute_reply.started":"2021-09-26T20:01:38.091867Z","shell.execute_reply":"2021-09-26T20:01:38.107366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('pixel_spacing_max: ', df_slide_details['pixel_spacing'].max())\nprint('pixel_spacing_min: ',df_slide_details['pixel_spacing'].min())","metadata":{"execution":{"iopub.status.busy":"2021-09-26T20:08:48.066705Z","iopub.execute_input":"2021-09-26T20:08:48.067556Z","iopub.status.idle":"2021-09-26T20:08:48.074163Z","shell.execute_reply.started":"2021-09-26T20:08:48.067518Z","shell.execute_reply":"2021-09-26T20:08:48.073078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('downsamples_max: ', df_slide_details['downsamples'].max())\nprint('downsamples_min: ',df_slide_details['downsamples'].min())","metadata":{"execution":{"iopub.status.busy":"2021-09-26T20:11:12.366478Z","iopub.execute_input":"2021-09-26T20:11:12.366788Z","iopub.status.idle":"2021-09-26T20:11:12.373766Z","shell.execute_reply.started":"2021-09-26T20:11:12.366755Z","shell.execute_reply":"2021-09-26T20:11:12.37295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('slide_dimension: ', df_slide_details['slide_dimension'].max())\nprint('slide_dimension: ',df_slide_details['slide_dimension'].min())","metadata":{"execution":{"iopub.status.busy":"2021-09-26T20:12:49.035514Z","iopub.execute_input":"2021-09-26T20:12:49.035811Z","iopub.status.idle":"2021-09-26T20:12:49.042599Z","shell.execute_reply.started":"2021-09-26T20:12:49.035777Z","shell.execute_reply":"2021-09-26T20:12:49.041676Z"},"trusted":true},"execution_count":null,"outputs":[]}]}