Пример #1
0
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')
Пример #2
0
"""
    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
            # print(originalImg[i,j,0])
            if pixel[0] == 255:
                try:
                    pixel.itemset(0,originalImg[i,j,0])
Пример #3
0
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")
Пример #4
0
from processing_functions import color_stuff as cs
from processing_functions import general_funcs as gf
import glob
import cv2

basedir = "/home/kauevestena/Dropbox/data/backup/temp/"
baseOutDir = "/home/kauevestena/Dropbox/data/gt/originals_complete_red/"

dirList = msc.getSubdirs(basedir)

subpaths = msc.subpathList(dirList,basedir)

msc.createDirStructure(baseOutDir,subpaths)


for folder in dirList:
    if msc.checkForImages(folder,'*.png'):
        print(folder)
        subpath = msc.removeBasedir(folder,basedir)
        outFolderPath = os.path.join(baseOutDir,subpath)
    
        for filepath in glob.glob(folder+"/*.png"):
            fileName = msc.filenameFromPath(filepath)
            outPath = os.path.join(outFolderPath,fileName)

            cs.save_one_band(filepath,outPath)


msc.telegram_bot_sendtext("band extraction terminated")

Пример #5
0
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)
Пример #6
0
#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")
Пример #7
0
 def __init__(self, imgpath):
     self.img_path = imgpath
     self.img_name = msc.filenameFromPath(imgpath)
     self.img_number = msc.fileNumberFromPathAsStr(imgpath)