{"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":"!pip install gdal","metadata":{"execution":{"iopub.status.busy":"2022-06-24T18:30:29.698451Z","iopub.execute_input":"2022-06-24T18:30:29.699039Z","iopub.status.idle":"2022-06-24T18:30:38.721320Z","shell.execute_reply.started":"2022-06-24T18:30:29.698966Z","shell.execute_reply":"2022-06-24T18:30:38.720123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I could Not install GDAL in any other Notebook since it resulted in errors. I tried other Datasets, that's why I forked Ihelon last HubMap competition, then I deleted all his snippets. \n\nNext, I copied his other new Kaggle Notebook with only images. Therefore this Notebook is almost FrankensteinISH, since it has parts of many aborted projects. And probably, is not making any sense, except to me and my learning path.","metadata":{}},{"cell_type":"markdown","source":"![](https://storage.googleapis.com/kaggle-organizations/3760/thumbnail.png)kaggle.com","metadata":{}},{"cell_type":"code","source":"import os, sys, random, gc, math, glob, time, pathlib\nimport numpy as np\nimport pandas as pd\nimport io, timeit, os, gc, pickle, psutil\nimport warnings\nimport cv2\nimport gdal\nimport osgeo\nimport json\nimport rasterio\nfrom rasterio.windows import Window\n\nimport seaborn as sns\nsns.set()\nsns.set_context(\"paper\", font_scale=1.2) \n\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nimport matplotlib.colors as cols\n\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-06-24T18:40:34.392070Z","iopub.execute_input":"2022-06-24T18:40:34.392676Z","iopub.status.idle":"2022-06-24T18:40:34.402708Z","shell.execute_reply.started":"2022-06-24T18:40:34.392638Z","shell.execute_reply":"2022-06-24T18:40:34.401794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by MPWARE https://www.kaggle.com/code/mpware/masks-quick-eda-updated-data/notebook\n\nprint('Python        : ' + sys.version.split('\\n')[0])\nprint('Numpy         : ' + np.__version__)\nprint('Pandas        : ' + pd.__version__)\nprint('Rasterio      : ' + rasterio.__version__)\nprint('GDal          : ' + osgeo.gdal.__version__)\nprint('OpenCV        : ' + cv2.__version__)","metadata":{"execution":{"iopub.status.busy":"2022-06-24T18:40:52.294330Z","iopub.execute_input":"2022-06-24T18:40:52.294708Z","iopub.status.idle":"2022-06-24T18:40:52.304561Z","shell.execute_reply.started":"2022-06-24T18:40:52.294675Z","shell.execute_reply":"2022-06-24T18:40:52.302788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport math\nimport time\nimport datetime\nimport glob\n\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sn\n\nimport json\nimport numpy as np\nimport os\nimport pandas as pd\nimport tifffile as tiff\nfrom matplotlib import colors\nfrom matplotlib import pyplot as plt\nfrom matplotlib.lines import Line2D\nfrom matplotlib_venn import venn2_unweighted","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:22:03.375704Z","iopub.execute_input":"2022-06-24T19:22:03.376126Z","iopub.status.idle":"2022-06-24T19:22:03.399692Z","shell.execute_reply.started":"2022-06-24T19:22:03.376092Z","shell.execute_reply":"2022-06-24T19:22:03.398792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\ntrain_images = glob.glob('/kaggle/input/hubmap-organ-segmentation/train_images/*.tiff')\ntest_images = glob.glob('/kaggle/input/hubmap-organ-segmentation/test_images/*.tiff')\n\ntrain_images = list(map(lambda x: os.path.basename(x), train_images))\ntest_images = list(map(lambda x: os.path.basename(x), test_images))","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:19:44.214721Z","iopub.execute_input":"2022-06-24T19:19:44.215735Z","iopub.status.idle":"2022-06-24T19:19:44.271379Z","shell.execute_reply.started":"2022-06-24T19:19:44.215684Z","shell.execute_reply":"2022-06-24T19:19:44.270144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\n# open and resize image\nimage = cv2.imread('/kaggle/input/hubmap-organ-segmentation/train_images/686.tiff')\nimage_resize = cv2.resize(image,(image.shape[1]//10,image.shape[0]//10), interpolation = cv2.INTER_CUBIC)","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:20:07.387583Z","iopub.execute_input":"2022-06-24T19:20:07.387991Z","iopub.status.idle":"2022-06-24T19:20:07.489790Z","shell.execute_reply.started":"2022-06-24T19:20:07.387952Z","shell.execute_reply":"2022-06-24T19:20:07.488838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\n# calculate colors\npixel_colors = image_resize.reshape((np.shape(image_resize)[0]*np.shape(image_resize)[1], 3))\nnorm = colors.Normalize(vmin=-1.,vmax=1.)\nnorm.autoscale(pixel_colors)\npixel_colors = norm(pixel_colors).tolist()\n\n# split channels\nb, g, r = cv2.split(image_resize)\n\n# scatter plot\nfig = plt.figure()\naxis = fig.add_subplot(1, 1, 1, projection='3d')\naxis.scatter(r.flatten(), g.flatten(), b.flatten(), facecolors=pixel_colors, marker='.')\naxis.set_xlabel('Red')\naxis.set_ylabel('Green')\naxis.set_zlabel('Blue')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:22:10.283390Z","iopub.execute_input":"2022-06-24T19:22:10.283785Z","iopub.status.idle":"2022-06-24T19:22:14.139078Z","shell.execute_reply.started":"2022-06-24T19:22:10.283750Z","shell.execute_reply":"2022-06-24T19:22:14.138037Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Georgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis\n\n# convert to hsv\nhsv_image = cv2.cvtColor(image_resize, cv2.COLOR_BGR2HSV)\nh, s, v = cv2.split(hsv_image)\n\n# scatter plot\nfig = plt.figure()\naxis = fig.add_subplot(1, 1, 1, projection='3d')\naxis.scatter(s.flatten(), h.flatten(), v.flatten(), facecolors=pixel_colors, marker='.')\naxis.set_xlabel('Saturation')\naxis.set_ylabel('Hue')\naxis.set_zlabel('Value')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:22:38.360054Z","iopub.execute_input":"2022-06-24T19:22:38.360445Z","iopub.status.idle":"2022-06-24T19:22:41.785971Z","shell.execute_reply.started":"2022-06-24T19:22:38.360408Z","shell.execute_reply":"2022-06-24T19:22:41.784847Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_PATH = \"../input/hubmap-organ-segmentation/\"","metadata":{"execution":{"iopub.status.busy":"2022-06-24T18:59:13.570776Z","iopub.execute_input":"2022-06-24T18:59:13.571133Z","iopub.status.idle":"2022-06-24T18:59:13.575789Z","shell.execute_reply.started":"2022-06-24T18:59:13.571103Z","shell.execute_reply":"2022-06-24T18:59:13.574662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_paths = sorted(glob.glob(os.path.join(DATA_PATH, 'train_images/*.tiff')))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-24T19:02:09.968788Z","iopub.execute_input":"2022-06-24T19:02:09.969195Z","iopub.status.idle":"2022-06-24T19:02:09.984983Z","shell.execute_reply.started":"2022-06-24T19:02:09.969153Z","shell.execute_reply":"2022-06-24T19:02:09.983951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Number of images: {len(image_paths)}\")","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:02:18.599464Z","iopub.execute_input":"2022-06-24T19:02:18.600171Z","iopub.status.idle":"2022-06-24T19:02:18.606115Z","shell.execute_reply.started":"2022-06-24T19:02:18.600115Z","shell.execute_reply":"2022-06-24T19:02:18.605352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Ihelon https://www.kaggle.com/code/ihelon/illustrations-kumapi390-eda\n\nimage_shapes = {}\n\nfor ind, image_path in enumerate(image_paths):\n    image = cv2.imread(image_path)\n    image_shapes[image.shape] = image_shapes.get(image.shape, 0) + 1\n    \nimage_shapes","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-24T19:02:45.864967Z","iopub.execute_input":"2022-06-24T19:02:45.865515Z","iopub.status.idle":"2022-06-24T19:05:06.803422Z","shell.execute_reply.started":"2022-06-24T19:02:45.865464Z","shell.execute_reply":"2022-06-24T19:05:06.801915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Ihelon https://www.kaggle.com/code/ihelon/illustrations-kumapi390-eda\n\nn_cols = 4\n\nfor ind, image_path in enumerate(image_paths):\n    image = cv2.imread(image_path)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    \n    if ind % n_cols == 0:\n        plt.figure(figsize=(16, 5))\n    plt.subplot(1, n_cols, ind % n_cols + 1)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    if ind % n_cols == n_cols - 1:\n        plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-24T19:06:31.427741Z","iopub.execute_input":"2022-06-24T19:06:31.428430Z","iopub.status.idle":"2022-06-24T19:12:15.136946Z","shell.execute_reply.started":"2022-06-24T19:06:31.428383Z","shell.execute_reply":"2022-06-24T19:12:15.136026Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Acknowledgements:\n\nIhelon https://www.kaggle.com/code/ihelon/illustrations-kumapi390-eda\n\nMPWARE https://www.kaggle.com/code/mpware/masks-quick-eda-updated-data/notebook\n\nGeorgii Kostiuchik https://www.kaggle.com/code/georgiikostiuchik/hubmap-exploratory-data-analysis","metadata":{}}]}