{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n        \nfrom utility_script import *","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{"trusted":true},"cell_type":"code","source":"example_index = -3","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img, sc_factor = read_img(TRAIN_DIR, TRAIN_FILE_NAMES[example_index])\nglomeruli = read_glomeruli(TRAIN_DIR, TRAIN_FILE_NAMES[example_index], sc_factor)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Look at image and mask"},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_mask(img, glomeruli)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Look at glomeruli (one example)"},{"metadata":{"trusted":true},"cell_type":"code","source":"example_glomeruli_index = 10\nzoom = 2 # how much you want to zoom out of the glomerulus you look at","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_glomeruli(img, glomeruli, example_glomeruli_index, zoom)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Explore the geometry\n\nWe sample random crops from the image. Typically models take such crops for image segmentation. One difficulty is the limited amount of training examples. We suggest random sampling of crops. Another issue is the imbalance of pixels belonging to glomeruli in contrast to pixels that don't. Thus it may be advantageous to sample crops close to glomeruli. \n\nIn the following we visualize the distribution of the number of glomeruli covered by a crop for the various techniques. \nWe also visulize the crops (their distribution and size) on the original image to get a feel for the sampling at use. \n\nNote that each sample crop has a smaller box inside. For instance this can be useful if we classify crops by their glomeruli containment. In this instance we would decide only if at least one glomerulus intersects the inner box whereas the model sees the full box and in this way has some surrounding information available. "},{"metadata":{"trusted":true},"cell_type":"code","source":"scope_size = 512 # crop in pxl\njiggle = 1 # std deviation from center (generated by pipeline)\noverlap = 1/6 # overlap of crops\ninternal_prop = 3/4 # how much is in the core (decisive region) of a sampled box","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# uncomment what you want to try\ngrid_pipe = get_scopes_on_grid(img, scope_size, jiggle, overlap, internal_prop, seed=0)\nrand_pipe = get_scopes_at_random(img, scope_size, internal_prop, seed=0)\nglom_pipe = get_scopes_near_glomeruli(img, glomeruli, scope_size, jiggle, internal_prop, seed=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nr_scopes = 200\nplot_distribution_glomeruli_in_core(img, glomeruli, grid_pipe, simulation_runs=1000)\nplot_scopes(img, glomeruli, grid_pipe, nr_scopes)\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nr_scopes = 200\nplot_distribution_glomeruli_in_core(img, glomeruli, rand_pipe, simulation_runs=1000)\nplot_scopes(img, glomeruli, rand_pipe, nr_scopes)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nr_scopes = 200\nplot_distribution_glomeruli_in_core(img, glomeruli, glom_pipe, simulation_runs=1000)\nplot_scopes(img, glomeruli, glom_pipe, nr_scopes)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}