Exemple #1
0
def check_input_file(path,masks):
    ret, img_1 = load_img(path+masks[0], grayscale=True)
    assert (ret == 0)

    height, width = img_1.shape
    num_img = len(masks)

    for next_index in range(1,num_img):
        next_ret, next_img=load_img(path+masks[next_index],grayscale=True)
        assert (next_ret ==0 )
        next_height, next_width = next_img.shape
        assert(height==next_height and width==next_width)
    return height, width
Exemple #2
0
def combine_all_mask(height, width,input_path,mask_pool):
    """

    :param height:
    :param width:
    :param input_path:
    :param mask_pool:
    :return: final mask from roads_mask and buildings_mask

    prior: road(1)>bulidings(2)
    """
    final_mask=np.zeros((height,width),np.uint8)
    for idx,file in enumerate(mask_pool):
        ret,img = load_img(input_path+file,grayscale=True)
        assert (ret == 0)
        label_value=0
        if 'road' in file:
            label_value =ROAD_VALUE
        elif 'building' in file:
            label_value=BUILDING_VALUE
        # label_value = idx+1
        for i in tqdm(range(height)):
            for j in range(width):
                if img[i,j]>=FOREGROUND:
                    print ("img[{},{}]:{}".format(i,j,img[i,j]))
                    if label_value==ROAD_VALUE:
                        final_mask[i,j]=label_value
                    elif label_value==BUILDING_VALUE and final_mask[i,j]!=ROAD_VALUE:
                            final_mask[i,j]=label_value
                            # print ("final_mask[{},{}]:{}".format(i, j, final_mask[i, j]))


    return final_mask
Exemple #3
0
def vote_per_image(height, width, path, masks):

    mask_list = []
    for tt in range(len(masks)):
        ret, img = load_img(path + masks[tt], grayscale=True)
        assert (ret == 0)
        mask_list.append(img)

    vote_mask = np.zeros((height, width), np.uint8)

    for i in tqdm(range(height)):
        for j in range(width):
            record = np.zeros(256, np.uint8)
            for n in range(len(mask_list)):
                mask = mask_list[n]
                pixel = mask[i, j]
                record[pixel] += 1
            """Alarming"""
            # if record.argmax()==0: # if argmax of 0 = 125 or 255, not prior considering background(0)
            #     record[0] -=1

            label = record.argmax()
            # print ("{},{} label={}".format(i,j,label))
            vote_mask[i, j] = label

    return vote_mask
import cv2
import sys, os
from ulitities.base_functions import load_img, get_file

input_path = '../../data/traindata/unet/buildings/label/'
output_path = '../../data/traindata/unet/buildings/visulize/'

if __name__ == '__main__':

    if not os.path.isdir(input_path):
        print("No input directory:{}".format(input_path))
        sys.exit(-1)
    if not os.path.isdir(output_path):
        print("No output directory:{}".format(output_path))
        os.mkdir(output_path)

    srcfiles, tt = get_file(input_path)
    assert (tt != 0)

    for index, file in enumerate(srcfiles):
        ret, img = load_img(file, grayscale=True)
        assert (ret == 0)

        img = img * 100
        filename = os.path.split(file)[1]
        outfile = os.path.join(output_path, filename)
        print(outfile)

        cv2.imwrite(outfile, img)
#coding:utf-8

import cv2
import numpy as np
import matplotlib.pyplot as plt

from ulitities.base_functions import load_img, compare_two_image_size

road_label_file = '../../data/originaldata/unet/roads/label/5.png'
building_label_file = '../../data/originaldata/unet/buildings/label/5.png'
output_file = '../../data/originaldata/all/label/5.png'


if __name__=='__main__':

    ret1, road_label = load_img(road_label_file, grayscale=True)
    assert(ret1==0)

    ret2, building_label = load_img(building_label_file, grayscale=True)
    assert (ret2== 0)

    compare_two_image_size(road_label, building_label, grayscale=True)

    height, width = road_label.shape

    output_label = np.zeros((height,width), np.uint8)
    index = np.where(road_label==1)
    output_label[index]=1
    idx = np.where(building_label == 1)
    output_label[idx] = 2
Exemple #6
0

if __name__ == '__main__':
    src_files,num = get_file(input_src_path)
    assert (num!=0)

    valid_labels = []
    if FLAG_USING_UNET:
        valid_labels = unet_labels
    else:
        valid_labels = segnet_labels

    for src_file in tqdm(src_files):
        label_file = input_label_path + os.path.split(src_file)[1]

        ret,src_img = load_img(src_file)
        assert(ret==0)

        ret,label_img = load_img(label_file, grayscale=True)
        assert (ret == 0)

        local_labels = np.unique(label_img)

        for tmp in local_labels:
            if tmp not in valid_labels:
                print ("\nWarning: some label is not valid value")
                print ("\nFile: {}".format(label_file))
                HAS_INVALID_VALUE = True


        if HAS_INVALID_VALUE == True: