{"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 numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport cv2\nimport seaborn \nimport matplotlib.pyplot as plt\nimport gc\n\nimport queue\nfrom shapely.geometry import Polygon, Point\nimport time\nimport json\nimport math\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-24T11:44:18.996833Z","iopub.execute_input":"2023-08-24T11:44:18.998148Z","iopub.status.idle":"2023-08-24T11:44:20.733682Z","shell.execute_reply.started":"2023-08-24T11:44:18.998092Z","shell.execute_reply":"2023-08-24T11:44:20.732067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Read Files","metadata":{}},{"cell_type":"code","source":"train_folder = \"/kaggle/input/hubmap-hacking-the-human-vasculature/train/\"\ntest_folder = \"/kaggle/input/hubmap-hacking-the-human-vasculature/test/\"","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:20.735509Z","iopub.execute_input":"2023-08-24T11:44:20.736043Z","iopub.status.idle":"2023-08-24T11:44:20.740363Z","shell.execute_reply.started":"2023-08-24T11:44:20.736015Z","shell.execute_reply":"2023-08-24T11:44:20.738933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wsi_fpath = \"/kaggle/input/hubmap-hacking-the-human-vasculature/wsi_meta.csv\"\ntile_fpath = \"/kaggle/input/hubmap-hacking-the-human-vasculature/tile_meta.csv\"\nsample_fpath = \"/kaggle/input/hubmap-hacking-the-human-vasculature/sample_submission.csv\"\npolygon_fpath = \"/kaggle/input/hubmap-hacking-the-human-vasculature/polygons.jsonl\"","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:20.743101Z","iopub.execute_input":"2023-08-24T11:44:20.743491Z","iopub.status.idle":"2023-08-24T11:44:20.753483Z","shell.execute_reply.started":"2023-08-24T11:44:20.743461Z","shell.execute_reply":"2023-08-24T11:44:20.752261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with open(polygon_fpath) as f:\n    polygon = [json.loads(line) for line in f]","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:20.756817Z","iopub.execute_input":"2023-08-24T11:44:20.757380Z","iopub.status.idle":"2023-08-24T11:44:24.285134Z","shell.execute_reply.started":"2023-08-24T11:44:20.757347Z","shell.execute_reply":"2023-08-24T11:44:24.283498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_files = os.listdir(train_folder)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:24.286909Z","iopub.execute_input":"2023-08-24T11:44:24.287293Z","iopub.status.idle":"2023-08-24T11:44:24.563342Z","shell.execute_reply.started":"2023-08-24T11:44:24.287263Z","shell.execute_reply":"2023-08-24T11:44:24.562587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wsi_df = pd.read_csv(wsi_fpath)\nsample_df = pd.read_csv(sample_fpath)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:24.564423Z","iopub.execute_input":"2023-08-24T11:44:24.564686Z","iopub.status.idle":"2023-08-24T11:44:24.591122Z","shell.execute_reply.started":"2023-08-24T11:44:24.564665Z","shell.execute_reply":"2023-08-24T11:44:24.590233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NP = len(polygon)\nNP","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:24.592305Z","iopub.execute_input":"2023-08-24T11:44:24.592665Z","iopub.status.idle":"2023-08-24T11:44:24.600597Z","shell.execute_reply.started":"2023-08-24T11:44:24.592621Z","shell.execute_reply":"2023-08-24T11:44:24.599679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_mat = np.load(\"/kaggle/input/hubmap-label/mask_mat.npy\")","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:24.601705Z","iopub.execute_input":"2023-08-24T11:44:24.602407Z","iopub.status.idle":"2023-08-24T11:44:27.446171Z","shell.execute_reply.started":"2023-08-24T11:44:24.602374Z","shell.execute_reply":"2023-08-24T11:44:27.444934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_mat[label_mat > 1] = 0","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:27.448107Z","iopub.execute_input":"2023-08-24T11:44:27.448519Z","iopub.status.idle":"2023-08-24T11:44:27.680390Z","shell.execute_reply.started":"2023-08-24T11:44:27.448478Z","shell.execute_reply":"2023-08-24T11:44:27.678115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_mat = label_mat.reshape(NP, 512, 512, 1)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:27.684966Z","iopub.execute_input":"2023-08-24T11:44:27.685426Z","iopub.status.idle":"2023-08-24T11:44:27.693624Z","shell.execute_reply.started":"2023-08-24T11:44:27.685381Z","shell.execute_reply":"2023-08-24T11:44:27.691840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_array = np.zeros((4), dtype = int)\n\nfor i in range(NP):\n    count_vec = np.bincount(label_mat[i].flatten())\n    for j in range(count_vec.shape[0]):\n        count_array[j] += count_vec[j]\n","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:27.695795Z","iopub.execute_input":"2023-08-24T11:44:27.696190Z","iopub.status.idle":"2023-08-24T11:44:29.339314Z","shell.execute_reply.started":"2023-08-24T11:44:27.696165Z","shell.execute_reply":"2023-08-24T11:44:29.337405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_fnames = []\nfor i in range(NP):\n    train_fnames.append(polygon[i][\"id\"])","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:29.341243Z","iopub.execute_input":"2023-08-24T11:44:29.341550Z","iopub.status.idle":"2023-08-24T11:44:29.349590Z","shell.execute_reply.started":"2023-08-24T11:44:29.341527Z","shell.execute_reply":"2023-08-24T11:44:29.348018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"time1 = time.time()\ni = 0\nL = 512\nL2 = L #256\nX_train = np.zeros((NP, L2, L2, 3), dtype =  np.uint8)\n\nfor i in range(NP):\n    \n    img = cv2.imread(train_folder + train_fnames[i] + \".tif\")[:,:,::-1]\n    #img = cv2.resize(img, (L2, L2))\n    X_train[i,:,:,:] = img#/127.5 - 1\n    \ntime2 = time.time()\n\ntime3 = np.round(time2 - time1)\n\nprint(time3, \"sec\")","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:44:29.351189Z","iopub.execute_input":"2023-08-24T11:44:29.351456Z","iopub.status.idle":"2023-08-24T11:45:14.312115Z","shell.execute_reply.started":"2023-08-24T11:44:29.351434Z","shell.execute_reply":"2023-08-24T11:45:14.311118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_name_df = pd.DataFrame({\"id\":train_fnames})\ntrain_name_df[\"count\"] = 1\n\ntile_df = pd.read_csv(tile_fpath)\ntile_df = tile_df.merge(train_name_df, on = \"id\", how = \"left\")\ntile_df = tile_df.query(\"count > 0\")","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:14.313461Z","iopub.execute_input":"2023-08-24T11:45:14.313788Z","iopub.status.idle":"2023-08-24T11:45:14.366049Z","shell.execute_reply.started":"2023-08-24T11:45:14.313754Z","shell.execute_reply":"2023-08-24T11:45:14.364784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Color Shift Function in HSV Color Space","metadata":{}},{"cell_type":"code","source":"def ColorConvert(img, shift = [0,0,0]):\n    \n    img2 = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)\n    for i in range(3):\n        \n        filter1 = (255 - img2[:,:,i]) >= shift[i]\n        filter2 = img2[:,:,i] >= -shift[i]\n        filter3 = filter1 & filter2\n        img2[:,:,i][filter3] = img2[:,:,i][filter3]  + shift[i]\n    \n    img3 = cv2.cvtColor(img2, cv2.COLOR_HSV2RGB)\n    \n    return img3","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:48:49.717529Z","iopub.execute_input":"2023-08-24T11:48:49.719041Z","iopub.status.idle":"2023-08-24T11:48:49.725817Z","shell.execute_reply.started":"2023-08-24T11:48:49.719005Z","shell.execute_reply":"2023-08-24T11:48:49.724927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_photo(img, title = \"\", convert = False, shift = [0,0,0]):\n    \n    N = img.shape[0]\n    \n    NC = 5\n    NR =  math.ceil(N/NC)\n    fig, ax = plt.subplots(NR, NC, figsize = (12, NR*2.3))\n    \n    for k in range(N):\n        i =  int(k/NC)\n        j = k % NC\n        \n        if N <= 5:\n            if convert:\n                ax[j].imshow(ColorConvert(img[k], shift))\n            else:\n\n                ax[j].imshow(img[k])\n\n            ax[j].tick_params(left = False, right = False , labelleft = False ,\n                        labelbottom = False, bottom = False)\n            \n        else:\n        \n            if convert:\n                ax[i,j].imshow(ColorConvert(img[k]))\n            else:\n\n                ax[i,j].imshow(img[k])\n\n            ax[i,j].tick_params(left = False, right = False , labelleft = False ,\n                        labelbottom = False, bottom = False)\n    \n    if title != \"\":\n        if N <= 5:\n            ax[2].set_title(title)\n        else:\n            ax[0,2].set_title(title)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:48:49.990352Z","iopub.execute_input":"2023-08-24T11:48:49.992382Z","iopub.status.idle":"2023-08-24T11:48:50.001704Z","shell.execute_reply.started":"2023-08-24T11:48:49.992333Z","shell.execute_reply":"2023-08-24T11:48:50.000192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_source= {}\nds_source = {}\nfor i in range(NP):\n    \n    id_source[tile_df[\"id\"].iloc[i]] = tile_df[\"source_wsi\"].iloc[i]\n    ds_source[tile_df[\"id\"].iloc[i]] = tile_df[\"dataset\"].iloc[i]","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:14.398497Z","iopub.execute_input":"2023-08-24T11:45:14.400118Z","iopub.status.idle":"2023-08-24T11:45:14.476360Z","shell.execute_reply.started":"2023-08-24T11:45:14.400035Z","shell.execute_reply":"2023-08-24T11:45:14.474731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"source_array = []\nds_array = []\nfor i in range(NP):\n    val = id_source[train_fnames[i]]\n    source_array.append(val)\n    val = ds_source[train_fnames[i]]\n    val = ds_array.append(val)\n    \n    \nsource_array = np.array(source_array)\nds_array = np.array(ds_array)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:14.477881Z","iopub.execute_input":"2023-08-24T11:45:14.478191Z","iopub.status.idle":"2023-08-24T11:45:14.486318Z","shell.execute_reply.started":"2023-08-24T11:45:14.478164Z","shell.execute_reply":"2023-08-24T11:45:14.484949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_df = pd.DataFrame({\"id\":train_fnames, \"source_wsi\":source_array, \"dataset\":ds_array})","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:14.487474Z","iopub.execute_input":"2023-08-24T11:45:14.487734Z","iopub.status.idle":"2023-08-24T11:45:14.501018Z","shell.execute_reply.started":"2023-08-24T11:45:14.487713Z","shell.execute_reply":"2023-08-24T11:45:14.499019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h_vals = []\ns_vals = []\nv_vals = []\nfor i in range(NP):\n    \n    h_vals.append(np.mean(cv2.cvtColor(X_train[i], cv2.COLOR_RGB2HSV)[:,:,0]))\n    s_vals.append(np.mean(cv2.cvtColor(X_train[i], cv2.COLOR_RGB2HSV)[:,:,1]))\n    v_vals.append(np.mean(cv2.cvtColor(X_train[i], cv2.COLOR_RGB2HSV)[:,:,2]))","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:14.502432Z","iopub.execute_input":"2023-08-24T11:45:14.502749Z","iopub.status.idle":"2023-08-24T11:45:17.371041Z","shell.execute_reply.started":"2023-08-24T11:45:14.502722Z","shell.execute_reply":"2023-08-24T11:45:17.370363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_df[\"H_val\"] = h_vals\nimg_df[\"S_val\"] = s_vals\nimg_df[\"V_val\"] = v_vals","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:17.371967Z","iopub.execute_input":"2023-08-24T11:45:17.372870Z","iopub.status.idle":"2023-08-24T11:45:17.379888Z","shell.execute_reply.started":"2023-08-24T11:45:17.372833Z","shell.execute_reply":"2023-08-24T11:45:17.378618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filter1 = img_df[\"dataset\"]==1\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 1)\ns1_idx1 = np.random.choice(np.where(filter2)[0], 100)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 2)\ns2_idx1 = np.random.choice(np.where(filter2)[0], 100)\n\nfilter1 = img_df[\"dataset\"]==2\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 1)\ns1_idx2 = np.random.choice(np.where(filter2)[0], 100)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 2)\ns2_idx2 = np.random.choice(np.where(filter2)[0], 100)\n\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 3)\ns3_idx2 = np.random.choice(np.where(filter2)[0], 100)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 4)\ns4_idx2 = np.random.choice(np.where(filter2)[0], 100)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:17.381355Z","iopub.execute_input":"2023-08-24T11:45:17.382073Z","iopub.status.idle":"2023-08-24T11:45:17.396697Z","shell.execute_reply.started":"2023-08-24T11:45:17.382047Z","shell.execute_reply":"2023-08-24T11:45:17.395548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## H-Distribution of HSV","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(2,1, figsize = (10, 7))\nsns.kdeplot(img_df[\"H_val\"].iloc[s1_idx1], label = \"source1, dataset1\", ax = ax[0], color = \"navy\")\nsns.kdeplot(img_df[\"H_val\"].iloc[s1_idx2], label = \"source1, dataset2\", ax = ax[1], color = \"navy\")\nsns.kdeplot(img_df[\"H_val\"].iloc[s2_idx1], label = \"source2, dataset1\", ax = ax[0], color = \"darkorange\")\nsns.kdeplot(img_df[\"H_val\"].iloc[s2_idx2], label = \"source2, dataset2\", ax = ax[1], color = \"darkorange\")\nsns.kdeplot(img_df[\"H_val\"].iloc[s3_idx2], label = \"source3, dataset2\", ax = ax[1], color = \"green\")\nsns.kdeplot(img_df[\"H_val\"].iloc[s4_idx2], label = \"source4, dataset2\", ax = ax[1], color = \"brown\")\n\nax[0].set_xlabel(\"\")\nax[1].set_xlabel(\"mean H value\")\nfor i in range(2):\n    ax[i].legend()\n    \n    ax[i].set_xlim(130, 150)\n    ax[i].set_title(\"dataset\" + str(i+1))\n    ax[i].grid()","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:17.398082Z","iopub.execute_input":"2023-08-24T11:45:17.398686Z","iopub.status.idle":"2023-08-24T11:45:18.026537Z","shell.execute_reply.started":"2023-08-24T11:45:17.398661Z","shell.execute_reply":"2023-08-24T11:45:18.025108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## S-Distribution of HSV","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(2,1, figsize = (10, 7))\nsns.kdeplot(img_df[\"S_val\"].iloc[s1_idx1], label = \"source1, dataset1\", ax = ax[0], color = \"navy\")\nsns.kdeplot(img_df[\"S_val\"].iloc[s1_idx2], label = \"source1, dataset2\", ax = ax[1], color = \"navy\")\nsns.kdeplot(img_df[\"S_val\"].iloc[s2_idx1], label = \"source2, dataset1\", ax = ax[0], color = \"darkorange\")\nsns.kdeplot(img_df[\"S_val\"].iloc[s2_idx2], label = \"source2, dataset2\", ax = ax[1], color = \"darkorange\")\nsns.kdeplot(img_df[\"S_val\"].iloc[s3_idx2], label = \"source3, dataset2\", ax = ax[1], color = \"green\")\nsns.kdeplot(img_df[\"S_val\"].iloc[s4_idx2], label = \"source4, dataset2\", ax = ax[1], color = \"brown\")\n\nax[0].set_xlabel(\"\")\nax[1].set_xlabel(\"mean S value\")\nfor i in range(2):\n    ax[i].legend()\n    \n    ax[i].set_xlim(50, 180)\n    ax[i].set_title(\"dataset\" + str(i+1))\n    ax[i].grid()","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:18.028071Z","iopub.execute_input":"2023-08-24T11:45:18.028407Z","iopub.status.idle":"2023-08-24T11:45:18.589166Z","shell.execute_reply.started":"2023-08-24T11:45:18.028378Z","shell.execute_reply":"2023-08-24T11:45:18.587689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## V-Distribution of HSV","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(2,1, figsize = (10, 7))\nsns.kdeplot(img_df[\"V_val\"].iloc[s1_idx1], label = \"source1, dataset1\", ax = ax[0], color = \"navy\")\nsns.kdeplot(img_df[\"V_val\"].iloc[s1_idx2], label = \"source1, dataset2\", ax = ax[1], color = \"navy\")\nsns.kdeplot(img_df[\"V_val\"].iloc[s2_idx1], label = \"source2, dataset1\", ax = ax[0], color = \"darkorange\")\nsns.kdeplot(img_df[\"V_val\"].iloc[s2_idx2], label = \"source2, dataset2\", ax = ax[1], color = \"darkorange\")\nsns.kdeplot(img_df[\"V_val\"].iloc[s3_idx2], label = \"source3, dataset2\", ax = ax[1], color = \"green\")\nsns.kdeplot(img_df[\"V_val\"].iloc[s4_idx2], label = \"source4, dataset2\", ax = ax[1], color = \"brown\")\n\nax[0].set_xlabel(\"\")\nax[1].set_xlabel(\"mean V value\")\nfor i in range(2):\n    ax[i].legend()\n    ax[i].set_xlim(140, 230)\n    ax[i].set_title(\"dataset\" + str(i+1))\n    ax[i].grid()","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:18.590731Z","iopub.execute_input":"2023-08-24T11:45:18.591065Z","iopub.status.idle":"2023-08-24T11:45:19.233975Z","shell.execute_reply.started":"2023-08-24T11:45:18.591039Z","shell.execute_reply":"2023-08-24T11:45:19.232600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.random.seed(1)\n\nfilter1 = img_df[\"dataset\"]==1\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 1)\ns1_idx1 = np.random.choice(np.where(filter2)[0], 5)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 2)\ns2_idx1 = np.random.choice(np.where(filter2)[0], 5)\n\nnp.random.seed(1)\n\nfilter1 = img_df[\"dataset\"]==2\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 1)\ns1_idx2 = np.random.choice(np.where(filter2)[0], 5)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 2)\ns2_idx2 = np.random.choice(np.where(filter2)[0], 5)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 3)\ns3_idx2 = np.random.choice(np.where(filter2)[0], 5)\n\nfilter2 = filter1 & (img_df[\"source_wsi\"] == 4)\ns4_idx2 = np.random.choice(np.where(filter2)[0], 5)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:19.235823Z","iopub.execute_input":"2023-08-24T11:45:19.236775Z","iopub.status.idle":"2023-08-24T11:45:19.251287Z","shell.execute_reply.started":"2023-08-24T11:45:19.236734Z","shell.execute_reply":"2023-08-24T11:45:19.249701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dataset1","metadata":{}},{"cell_type":"code","source":"plot_photo(X_train[s1_idx1], \"source1 from dataset1\")\nplot_photo(X_train[s2_idx1], \"source2 from dataset1\")","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:19.252632Z","iopub.execute_input":"2023-08-24T11:45:19.252980Z","iopub.status.idle":"2023-08-24T11:45:21.065986Z","shell.execute_reply.started":"2023-08-24T11:45:19.252954Z","shell.execute_reply":"2023-08-24T11:45:21.063850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dataset2 (Raw)","metadata":{}},{"cell_type":"code","source":"plot_photo(X_train[s1_idx2], \"source1 from dataset2\")\nplot_photo(X_train[s2_idx2], \"source2 from dataset2\")\nplot_photo(X_train[s3_idx2], \"source3 from dataset2\")\nplot_photo(X_train[s4_idx2], \"source4 from dataset2\")","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:21.071794Z","iopub.execute_input":"2023-08-24T11:45:21.072677Z","iopub.status.idle":"2023-08-24T11:45:25.012981Z","shell.execute_reply.started":"2023-08-24T11:45:21.072643Z","shell.execute_reply":"2023-08-24T11:45:25.011467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dataset2 (Color Shifted)","metadata":{}},{"cell_type":"code","source":"shift1 = [-3,-10,5]\nshift3 = [-5,-20,20]\nshift4 = [-3,-15,10]","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:25.014523Z","iopub.execute_input":"2023-08-24T11:45:25.014877Z","iopub.status.idle":"2023-08-24T11:45:25.020959Z","shell.execute_reply.started":"2023-08-24T11:45:25.014831Z","shell.execute_reply":"2023-08-24T11:45:25.019186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_photo(X_train[s1_idx2], \"source1 from dataset2 Color shifted\", True, shift1)\nplot_photo(X_train[s2_idx2], \"source2 from dataset2\")\nplot_photo(X_train[s3_idx2], \"source3 from dataset2, Color shifted\", True, shift3)\nplot_photo(X_train[s4_idx2], \"source4 from dataset2, Color shifted\",True, shift4)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:48:58.748715Z","iopub.execute_input":"2023-08-24T11:48:58.749203Z","iopub.status.idle":"2023-08-24T11:49:02.309299Z","shell.execute_reply.started":"2023-08-24T11:48:58.749170Z","shell.execute_reply":"2023-08-24T11:49:02.308276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ratio of Positive Pixel","metadata":{}},{"cell_type":"code","source":"tile_df[[\"dataset\", \"source_wsi\", \"count\"]].groupby([\"dataset\", \"source_wsi\"]).count()","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:28.568077Z","iopub.execute_input":"2023-08-24T11:45:28.569174Z","iopub.status.idle":"2023-08-24T11:45:28.588965Z","shell.execute_reply.started":"2023-08-24T11:45:28.569139Z","shell.execute_reply":"2023-08-24T11:45:28.587938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c1_array = np.zeros(NP, dtype = int)\n\nfor i in range(NP):\n    c1_array[i] = np.sum(label_mat[i] == 1)\n    \nimg_df[\"c1\"] = c1_array/512**2","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:28.590066Z","iopub.execute_input":"2023-08-24T11:45:28.590400Z","iopub.status.idle":"2023-08-24T11:45:28.785817Z","shell.execute_reply.started":"2023-08-24T11:45:28.590370Z","shell.execute_reply":"2023-08-24T11:45:28.784833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(2, 2, figsize = (12, 9))\nfilter1 = (img_df[\"dataset\"] == 1) & (img_df[\"source_wsi\"] == 1)\nsns.kdeplot(data = img_df[filter1], x = \"c1\", label = \"dataset1\", ax = ax[0,0])\nfilter1 = (img_df[\"dataset\"] == 2) & (img_df[\"source_wsi\"] == 1)\nsns.kdeplot(data = img_df[filter1], x = \"c1\", label = \"dataset2\", ax = ax[0,0])\nax[0,0].set_title(\"source wsi 1\")\n\nfilter1 = (img_df[\"dataset\"] == 1) & (img_df[\"source_wsi\"] == 2)\nsns.kdeplot(data = img_df[filter1], x = \"c1\", label = \"dataset1\", ax = ax[0,1])\nfilter1 = (img_df[\"dataset\"] == 2) & (img_df[\"source_wsi\"] == 2)\nsns.kdeplot(data = img_df[filter1], x = \"c1\", label = \"dataset2\", ax = ax[0,1])\nax[0,1].set_title(\"source wsi 2\")\n\nfilter1 = (img_df[\"dataset\"] == 2) & (img_df[\"source_wsi\"] == 3)\nsns.kdeplot(data = img_df[filter1], x = \"c1\", label = \"dataset2\", ax = ax[1,0], color = \"darkorange\")\nax[1,0].set_title(\"source wsi 3\")\n\nfilter1 = (img_df[\"dataset\"] == 2) & (img_df[\"source_wsi\"] == 4)\nsns.kdeplot(data = img_df[filter1], x = \"c1\", label = \"dataset2\", ax = ax[1,1], color = \"darkorange\")\nax[1,1].set_title(\"source wsi 4\")\n\n\nfor i in range(2):\n    for j in range(2):\n        ax[i,j].legend()\n        ax[i,j].set_xlim(0, 0.35)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T11:45:28.786921Z","iopub.execute_input":"2023-08-24T11:45:28.787185Z","iopub.status.idle":"2023-08-24T11:45:29.711707Z","shell.execute_reply.started":"2023-08-24T11:45:28.787156Z","shell.execute_reply":"2023-08-24T11:45:29.709870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}