From 7b611912dc361e54e1f0e0d00cf8e05fb363e175 Mon Sep 17 00:00:00 2001 From: Maciej Sobkowiak Date: Wed, 16 Feb 2022 23:46:03 +0100 Subject: [PATCH] jupyter training --- main.ipynb | 0 requirements.txt | Bin 4618 -> 5922 bytes transform_data.py | 63 ---------------------------------------------- 3 files changed, 63 deletions(-) create mode 100644 main.ipynb delete mode 100644 transform_data.py diff --git a/main.ipynb b/main.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index ec8345ce55ea66a35a5ed78b48142d9a5087ca36..29e7ca9092f059000437cbb2817392b258090d50 100644 GIT binary patch delta 1263 zcmcgsO=}ZT6g?9fL&Z{ph?Eknpv%e3q;0STK}m~*+QyHDf*YBplQf#igvn@dm8IZH zn1u^h>Z%}u%)(#L-{9Zz-1|Dg;L3$Eym@c#yC3J?d+xlu^||`~YbC)e3^9U_7-Iyu z%f~|%b*}aAUse|?1KuS#re2p%pn9TJqlTOQSokpYX_=^{OWCGaVhNY=06Vykhgics zt}gl*(0&_^J`Fv!HLApR5Hivj5o0;D40wJ?zY)_T#sh+^*3aA}WmJoWx zGTA(z668P=8KTEq2ag4{)Gp!MnPqLW3RP@yd1^S~_txBLLbpRar^ArJ>Z&_ofI%7+ zSJUI-!L^8Cdm7Bv9!Z`3)VHpt-->JHQ`UNfH(Gg#RZq{0yDPrJ62N(vJng2NS(i4g zeQBTo&M)uK(A9SBF$HsHYsCUOm%4Q*mjnfDPwj*tvTCVQvMYTyOzP(Ub}w**3~tsg zy)E379wy8^P$y#+IGmwY)$Hfu$HH|<=7bRqnIwXgua<>Z8rB8N1ft~jk2&=xrKbOt zQ}dLPt~90hdG@v`Ka1nB%tFh*U{`jwR4SAMc1wmW=3olvCuwE*#`NM$mr`V#{q9i9 zo(=Dq9Wp>n1Et3`?ULb;ff&*%Qm^qGUvix;Jqo8}u4L$C$YaWebqac%fP}_|*YcM! o6s_t&zScpnF>jA2*MJhKo8ECG{{2`01J34j8# ZfDD!bvoa4p0i(VV0<)?Vz5$bl7MuXM7RLYp diff --git a/transform_data.py b/transform_data.py deleted file mode 100644 index ebcc3e7..0000000 --- a/transform_data.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt - -import cv2 as cv -import rasterio as rio - -RASTERS_DIR = './data/data/train_features' -IMAGES_DIR = './images/' -FC_DIR = "fc" - - -def load_img(path, expand_dim=False): - img = cv.imread(path) - img = img / 255.0 - if expand_dim: - img = np.expand_dims(img, axis=0) - - return img - - -def create_folder(name, path): - n = os.path.join(path, name) - if not os.path.exists(n): - os.makedirs(n) - return n - - -def scale(band): - return band/np.max(band) - - -def convert_raster_to_image(rasters_dir, - rgb_path=None, - false_color_path=None): - - b2 = scale(rio.open(rasters_dir+'/B02.tif').read().reshape(512, 512, 1)) - b3 = scale(rio.open(rasters_dir+'/B03.tif').read().reshape(512, 512, 1)) - b4 = scale(rio.open(rasters_dir+'/B04.tif').read().reshape(512, 512, 1)) - b8 = scale(rio.open(rasters_dir+'/B08.tif').read().reshape(512, 512, 1)) - - file_name = rasters_dir.split(os.sep)[-1] - - rgb = np.dstack([b4, b3, b2]) - - plt.imsave(fname=rgb_path + f'/{file_name}.jpeg', - arr=rgb) - - fc = np.dstack([b8, b3, b2]) - - plt.imsave(fname=false_color_path + f'/{file_name}.jpeg', - arr=fc) - - -def transform_photo(raster_dir): - dp = create_folder(raster_dir, IMAGES_DIR) - fc = create_folder(FC_DIR, dp) - convert_raster_to_image(os.path.join(RASTERS_DIR, raster_dir), dp, fc) - - -if __name__ == "__main__": - for d in os.listdir(RASTERS_DIR): - transform_photo(d)