from processing_functions import misc from processing_functions import general_funcs as gf import os import cv2 """ initially i've trated grass and soil vegtation as "vegetation", but now i will only use not grass vegetation """ classifiedPath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/already_classified" toClassifyFolder = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/reclassification" originalsPath = "/home/kaue/data/extracted_images/2019-07-11-16-21-46/ngr" classifiedList = misc.orderedFileList(classifiedPath,'*.png') for path in classifiedList: # print(path) filename = misc.filenameFromPath(path) originalImgPath = os.path.join(originalsPath,misc.modFilenameExt(filename,'.jpg')) outPath = os.path.join(toClassifyFolder,filename) print(originalImgPath) classifiedImg = cv2.imread(path) originalImg = cv2.imread(originalImgPath) for i,column in enumerate(classifiedImg): for j,pixel in enumerate(column): # as there are only black or white pixels, we can test only a channel
import os import glob import random from processing_functions import misc as msc from shutil import copyfile # define the number of samples you want n_samples = 50 imgsPath = os.environ['HOME'] + '/data/extracted_images/2019-07-11-16-21-46/ngr' out_path = os.environ[ 'HOME'] + '/data/extracted_images/samples/' + msc.find_datetime_String( imgsPath) # print(out_path) msc.createDir(out_path) imList = msc.orderedFileList(imgsPath) n = len(imList) print(n) for i in range(n_samples): imSample = imList[random.randint(0, n - 1)] filename = msc.filenameFromPath(imSample) # print(filename) copyfile(imSample, os.path.join(out_path, filename)) print('fim')
if print_dimensions: print(w, h, new_w, new_h) new_size = (new_w, new_h) new_image = Image.new("RGB", new_size) new_image.paste(image, ((new_size[0] - image.size[0]) // 2, (new_size[1] - image.size[1]) // 2)) new_image.save(imgpath.replace('.png', '_outline.png')) ####### # naming for the local folder: outlocalfolder = "phase3_reloaded" pickles_list = msc.orderedFileList(vd.PICKLES_PATH, '*.pickle') t1 = time.time() #print(pickles_list) dataDict = {} for picklepath in pickles_list: fname = msc.filenameFromPathWtithoutExt(picklepath) #print(fname) with open(picklepath, 'rb') as picklefile: dataDict[fname] = pickle.load(picklefile) #print(dataDict)
import os from processing_functions import misc as msc from processing_functions import color_stuff as cs import glob basedir = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46" onlyCheck = False dirList = msc.getSubdirs(basedir) for folder in dirList: if msc.checkForImages(folder, '*.png'): imList = msc.orderedFileList(folder, '*.png', True) for filePath in imList: print(filePath) if cs.checkIfPixVal(filePath): if onlyCheck: print(filePath) else: cs.chg_specific_pix_val(filePath, filePath)
out_dirs = ['orig_resiz','overlay','masks','ndvi','only_veg'] msc.createDirStructure(out_basepath,out_dirs) outpaths = {} for name in out_dirs: outpaths[name] = os.path.join(out_basepath,name) # imgs_path = "/home/kaue/data/extracted_images/2019-07-11-16-21-46/ngr" # imgs_path = "/home/kaue/data/extracted_images/red_band" imgs_path = "/home/kaue/data/extracted_images/newextracted" img_list = msc.orderedFileList(imgs_path,extension='*.png') img_list = sorted(img_list) # del img_list[0:225] print(img_list[0:5]) for i,img_path in enumerate(img_list): t1 = time.time() img_name = msc.fileNumberFromPathAsStr(img_path) out_orig = os.path.join(vd.PREDS_PATH,img_name+'.png') out_pred = os.path.join(vd.PREDS_PATH,img_name+'_pred.png') dest_orig = os.path.join(outpaths['orig_resiz'],img_name+'.png')
from processing_functions import misc as msc from processing_functions import color_stuff as cs import os path = "/home/kaue/data/politecnico_v2/val" destpath = "/home/kaue/data/politecnico_v2/downsized" filelist = msc.orderedFileList(path) for filepath in filelist: filename = msc.fileNumberFromPathAsStr(filepath)+'.png' print(filename) cs.allBlackImg(filepath,os.path.join(destpath,filename),(512,512))
strToContain = 'color' pathlist = msc.getSubdirs(basedir) # sizes = np.empty(len(pathlist), dtype=int) # print(sizes) # for i,path in enumerate(pathlist): # sizes[i] = path.count('/') # print(sizes) # max_lvl = np.max(sizes) # print(max_lvl) for path in pathlist: if msc.checkForImages(path,'*.png'): parent = msc.get_parent_dir(path)S imgList = msc.orderedFileList(path,'*.png') for imgPath in imgList: if strToContain in imgPath: filename = msc.filenameFromPath(imgPath) newfilename = filename.replace(strToReplace,strToAdd) print(newfilename) move(imgPath,os.path.join(parent,newfilename)) # os.removedirs(path) msc.telegram_bot_sendtext("copying terminated")
from processing_functions import misc as msc from processing_functions import general_funcs as gf import os in_out_list = [("/home/kaue/Dropbox/data/gt/versions/only_trees", "/home/kaue/Dropbox/data/gt_downsized/only_trees"), ("/home/kaue/Dropbox/data/gt/versions/with_terrain_veg", "/home/kaue/Dropbox/data/gt_downsized/with_terrain_veg")] for inoutpair in in_out_list: try: os.makedirs(inoutpair[1]) except: pass imgList = msc.orderedFileList(inoutpair[0], '*.png') for imgpath in imgList: imgname = msc.filenameFromPath(imgpath) outpath = os.path.join(inoutpair[1], imgname) # print(outpath) gf.resize_and_save(imgpath, outpath)
from processing_functions import misc as msc basepath = "/media/kauevestena/data/Semantic-Segmentation-Suite/Cityscapes" ext = '*.png' folderlist = msc.getSubdirs(basepath) for folder in folderlist: if msc.checkForImages(folder, ext): filelist = msc.orderedFileList(folder, ext) print(folder) print(len(filelist))
#script to classify vegetation and no vegatation in a manualy classified in white for vegetation and anything to non-vegetation from processing_functions import misc as msc from processing_functions import color_stuff as cs import datetime import os # import cv2 # inputpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/regular" inputpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/reclassification" # outpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/already_classified" outpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/reclassification_blackwhite" imagelist = msc.orderedFileList(inputpath, extension='*.png') minDate = datetime.datetime(year=2019, day=17, month=7) for imgpath in imagelist: filedate = msc.getModTime(imgpath) if filedate > minDate: savepath = os.path.join(outpath, msc.filenameFromPath(imgpath)) # cs.remove_other_classes(imgpath,savepath,255,255,255) cs.remove_other_classes(imgpath, savepath, 0, 0, 0, 255, 255, 255) print(imgpath) msc.telegram_bot_sendtext("GT classification ended")
created to open all images, if you want to manually annotate with kolourpaint """ defaultPath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/regular" basePath2 = "/home/kaue/data/extracted_images/2019-07-11-16-21-46/ngr" if len(sys.argv) < 2: # print("insert pathname") # sys.exit() path = defaultPath else: path = sys.argv[1] filePathList = msc.orderedFileList(path,'*.png',1) basePath = msc.pathWithoutFilename(sys.argv[0]) #create file to store the last opened image: lastOpenedPath = os.path.join(basePath,'last_opened.txt') if not os.path.exists(lastOpenedPath): # storageFile = open(lastOpenedPath,'w') # storageFile.close() msc.writeToFile(lastOpenedPath,"") if os.stat(lastOpenedPath).st_size == 0: # storageFile = open(lastOpenedPath,'w') # storageFile.write("-1") # storageFile.close()]
import os from processing_functions import misc as msc from processing_functions import color_stuff as cs from processing_functions import general_funcs as gf import glob basedir = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46" dirList = msc.getSubdirs(basedir) for folder in dirList: if msc.checkForImages(folder): imList = msc.orderedFileList(folder) for filePath in imList: gf.saveJPG_as_PNG(filePath, True)
width = 1024 height = 1024 FPS = 15 seconds = 127 fourcc = VideoWriter_fourcc(*'MP42') video = VideoWriter(videopath, fourcc, float(FPS), (width, height)) ############3 for name in out_dirs: outpaths[name] = os.path.join(out_basepath, name) imgs_path = "/home/kaue/data/extracted_images/2019-07-11-16-21-46/ngr" img_list = msc.orderedFileList(imgs_path) for i, img_path in enumerate(img_list): t1 = time.time() img_name = msc.fileNumberFromPathAsStr(img_path) dest_orig = os.path.join(outpaths['orig_resiz'], img_name + '.png') dest_pred = os.path.join(outpaths['masks'], img_name + '.png') dest_onlyveg = os.path.join(outpaths['only_veg'], img_name + '.png') dest_ndvi = os.path.join(outpaths['ndvi'], img_name + '.png') dest_overlay = os.path.join(outpaths['overlay'], img_name + '.png') # allpaths = [dest_ndvi,dest_onlyveg,dest_orig,dest_overlay,dest_pred]
import cv2 import numpy as np import time outfolder = msc.joinToHome("data/cnn_output/ndvi_v2") input_path = msc.joinToHome("data/cnn_output/only_veg") stats_path = msc.joinToHome("data/cnn_output/ndvi_stats.csv") if os.path.exists(stats_path): os.remove(stats_path) img_inputlist = msc.orderedFileList(input_path,'*.png') for i,imgpath in enumerate(img_inputlist): t1 = time.time() imgname = msc.filenameFromPathWtithoutExt(imgpath) outpath = os.path.join(outfolder,imgname+'.png') print(outpath) cs.gen_uint8_NDVI(imgpath,outpath,absolute_scale=True,print_stats=True)
if ckptnumber < 500: if not i % 25 == 0: del validCkptFolders[i] elif ckptnumber < 900: if not i % 10 == 0: del validCkptFolders[i] elif ckptnumber < 1000: if not i % 5 == 0: del validCkptFolders[i] print(len(validCkptFolders)) print(validCkptFolders) # Ground Truth Images gtImages = msc.joinToHome("/Dropbox/data/gt/originals") gtImagesList = msc.orderedFileList(gtImages, '*.png') # print(gtImagesList) # Ground Truth Masks (gtm) gtMasksVersions = msc.joinToHome("/Dropbox/data/gt_downsized") gtmDirs = msc.getSubdirs(gtMasksVersions) print(gtmDirs) listOfListsOnDirs = [] for dirPath in gtmDirs: listOfListsOnDirs.append(msc.orderedFileList(dirPath, '*.png')) # list of images and ground truth versions imgs_and_gts = []
def getDBlist(): return msc.orderedFileList(TINYDBS_PATH,'*.json')