{"cells":[{"metadata":{},"cell_type":"markdown","source":"In this notebook, I make dataframes containing the white pixel locations in each floor image. I wanted just the hallway areas, but I am having trouble creating a contour around the building. I use these dataframes to push predictions into the hallway areas (hopefully) in my notebook https://www.kaggle.com/therocket290/indoor-navigation-push-to-hallway-post-process."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport scipy.stats as stats\nfrom pathlib import Path\nimport glob\nimport pickle\nimport matplotlib.pyplot as plt\nimport joblib\n\nimport random\nimport os\nimport glob\nimport json\n\nimport cv2\nfrom PIL import Image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sites = []\nfor path in os.listdir('../input/wifi-features-all'):\n    if (len(path.split('_')[0])>20) and (not path.split('_')[0] in sites):\n        sites.append(path.split('_')[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"thresh_path = '../input/threshold-images/'\nmeta_path = '../input/indoor-location-navigation/metadata/'","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Example"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Plot the training Data For an example Floor\nexample_site = '5dbc1d84c1eb61796cf7c010'\nexample_floorNo = 'F7'\nfloors = os.listdir(meta_path+example_site)\narray = joblib.load(thresh_path+'thresh_list_'+example_site+'.pkl')\narray = array[floors.index(example_floorNo)]\nwhite_area = []\nfor (x,y) in zip(np.where(array[:,:,1] == 0)[0],np.where(array[:,:,1] == 0)[1]):\n    white_area.append( (x, y) )\ndf = pd.DataFrame(white_area, columns=['x','y'])\ndf.plot(x='x', y='y', kind='scatter')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"I will work on dropping the pixels outside the building."},{"metadata":{"trusted":true},"cell_type":"code","source":"del array, white_area","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"base=\"../input/indoor-location-navigation\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for site in sites:\n    print(site)\n    site_white_areas = []\n    floors = os.listdir(meta_path+site)\n    array = joblib.load(thresh_path+'thresh_list_'+site+'.pkl')\n    print(site+ ' ' , floors)\n    for floor in floors:\n        floor_array = array[floors.index(floor)]\n        floor_white_area = []\n        for (x,y) in zip(np.where(floor_array[:,:,1] == 0)[0],np.where(floor_array[:,:,1] == 0)[1]):\n            floor_white_area.append( (x, y) )\n        site_white_areas.append(floor_white_area)\n        floor_df = pd.DataFrame(floor_white_area)\n        floor_df.columns = ['x','y']\n        \n        ######\n        floor_df['x2'] = floor_array.shape[0] - floor_df['x']\n        \n        json_plan_filename = f\"{base}/metadata/{site}/{floor}/floor_info.json\"\n        with open(json_plan_filename) as json_file:\n            json_data = json.load(json_file)\n\n        width_meter = json_data[\"map_info\"][\"width\"]\n        height_meter = json_data[\"map_info\"][\"height\"]\n        \n        # Convert to meters\n        floor_df['x2'] = floor_df['x2'] * height_meter / floor_array.shape[0]\n        floor_df['y2'] = floor_df['y'] * width_meter / floor_array.shape[1]\n        \n        #######\n        floor_df.to_csv('white_area_'+site+'_'+floor+'.csv', index=False)","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}