예제 #1
0
def compute_two(img_path, gt_path, img_path2, gt_path2):
    out = load_image(img_path)
    # gt = load_image(gt_path)
    # 不要用interpolation=cv.INTER_NEAREST,不然结果不一样,估计opencv bug
    gt = cv.resize(load_image(gt_path), (512, 256), cv.INTER_NEAREST)
    # val_gt_erode paired with [0,0,0]label value
    # label order: R G B
    # num_classes = len(label_values)

    gt = util.reverse_one_hot(util.one_hot_it(gt, label_values))
    output_image = util.reverse_one_hot(util.one_hot_it(out, label_values))

    out2 = load_image(img_path2)
    gt2 = cv.resize(load_image(gt_path2), (512, 256), cv.INTER_NEAREST)
    gt2 = util.reverse_one_hot(util.one_hot_it(gt2, label_values))
    output_image2 = util.reverse_one_hot(util.one_hot_it(out2, label_values))

    out_all = np.zeros((2, 256, 512))
    out_all[0, :, :] = output_image
    out_all[1, :, :] = output_image2
    gt_all = np.zeros((2, 256, 512))
    gt_all[0, :, :] = gt
    gt_all[1, :, :] = gt2
    out_all = out_all.astype(int)
    gt_all = gt_all.astype(int)

    running_metrics_val.update(gt_all, out_all)
예제 #2
0
def img_to_label_list(GT_path, PRED_path):
    GT_img = cv.cvtColor(cv.imread(GT_path, 1), cv.COLOR_BGR2RGB)
    PRED_img = cv.cvtColor(cv.imread(PRED_path, 1), cv.COLOR_BGR2RGB)
    label_values_RGB = [(0, 0, 0), (255, 250, 250), (248, 248, 255),
                        (211, 211, 211), (255, 99, 71), (255, 250, 240),
                        (139, 69, 19), (250, 240, 230), (0, 206, 209),
                        (255, 215, 0), (205, 92, 92), (255, 228, 196),
                        (255, 218, 185), (255, 222, 173), (175, 238, 238),
                        (255, 248, 220), (47, 79, 79), (255, 250, 205),
                        (255, 245, 238), (240, 255, 240), (245, 255, 250),
                        (240, 255, 255), (240, 248, 255), (230, 230, 250),
                        (255, 240, 245), (255, 228, 225), (255, 255, 240),
                        (105, 105, 105), (112, 128, 144), (190, 190, 190),
                        (245, 245, 245), (100, 149, 237), (65, 105, 225),
                        (0, 191, 255), (135, 206, 250), (70, 130, 180),
                        (255, 228, 181), (250, 235, 215), (95, 158, 160),
                        (0, 250, 154), (255, 255, 0), (255, 239, 213),
                        (255, 235, 205)]

    GT_precode = util.reverse_one_hot(util.one_hot_it(GT_img,
                                                      label_values_RGB))
    PRED_precode = util.reverse_one_hot(
        util.one_hot_it(PRED_img, label_values_RGB))
    GT_flat = GT_precode.flatten()
    PRED_flat = PRED_precode.flatten()
    return GT_flat, PRED_flat
예제 #3
0
def compute_one(img_path, gt_path):
    out = load_image(img_path)
    gt = load_image(gt_path)
    # val_gt_erode paired with [0,0,0]label value
    # label order: R G B
    # num_classes = len(label_values)
    gt = util.reverse_one_hot(util.one_hot_it(gt, label_values))
    output_image = util.reverse_one_hot(util.one_hot_it(out, label_values))
    running_metrics_val.update(gt, output_image)
예제 #4
0
def img_to_label_list_not_for_change_type(GT_path, PRED_path,
                                          label_values_RGB):
    GT_img = cv.cvtColor(cv.imread(GT_path, 1), cv.COLOR_BGR2RGB)
    PRED_img = cv.cvtColor(cv.imread(PRED_path, 1), cv.COLOR_BGR2RGB)
    GT_precode = util.reverse_one_hot(util.one_hot_it(GT_img,
                                                      label_values_RGB))
    PRED_precode = util.reverse_one_hot(
        util.one_hot_it(PRED_img, label_values_RGB))
    GT_flat = GT_precode.flatten()
    PRED_flat = PRED_precode.flatten()
    return GT_flat, PRED_flat
예제 #5
0
def compute_one(img_path,gt_path):
    out = load_image(img_path)
    # gt = load_image(gt_path)
    # 不要用interpolation=cv.INTER_NEAREST,不然结果不一样,估计opencv bug
    # 上面说法错了,要用interpolation=cv.INTER_NEAREST
    gt = cv.resize(load_image(gt_path),(512,256),interpolation=cv.INTER_NEAREST)
    # val_gt_erode paired with [0,0,0]label value
    # label order: R G B
    # num_classes = len(label_values)

    gt = util.reverse_one_hot(util.one_hot_it(gt, label_values))
    output_image = util.reverse_one_hot(util.one_hot_it(out, label_values))
    running_metrics_val.update(gt, output_image)
예제 #6
0
파일: draw_bar.py 프로젝트: Spritea/Hotkey
def compute_one(img_path):
    label_values_RGB_SCPA_WC = [[0,0,0], [128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128]]
    gt = load_image(img_path)
    out = util.reverse_one_hot(util.one_hot_it(gt, label_values_RGB_SCPA_WC))
    out_str = 'out.png'
    cv.imwrite(out_str,out)
    image = Image.open(out_str)
    a = image.getcolors()
    a.sort(key=takesecond)
    print(a)
    print("color kind: %d" % len(a))
    return a
                    (0, 206, 209), (255, 215, 0), (205, 92, 92),
                    (255, 228, 196), (255, 218, 185), (255, 222, 173),
                    (175, 238, 238), (255, 248, 220), (47, 79, 79),
                    (255, 250, 205), (255, 245, 238), (240, 255, 240),
                    (245, 255, 250), (240, 255, 255), (240, 248, 255),
                    (230, 230, 250), (255, 240, 245), (255, 228, 225),
                    (255, 255, 240), (105, 105, 105), (112, 128, 144),
                    (190, 190, 190), (245, 245, 245), (100, 149, 237),
                    (65, 105, 225), (0, 191, 255), (135, 206, 250),
                    (70, 130, 180), (255, 228, 181), (250, 235, 215),
                    (95, 158, 160), (0, 250, 154), (255, 255, 0),
                    (255, 239, 213), (255, 235, 205)]
for k in tqdm(range(len(GT_Str))):
    gt = load_image(GT_Str[k])
    # out=util.reverse_one_hot(util.one_hot_it(gt,label_values_RGB_SCPA_WC))
    out = util.reverse_one_hot(util.one_hot_it(gt, candy_color_list))
    out_str = out_prefix + Path(GT_Str[k]).name
    cv.imwrite(out_str, out)
    # print("kk")

image = Image.open(out_str)
a = image.getcolors()
a.sort(key=takefirst, reverse=True)
print(a)
print("color kind: %d" % len(a))

image = Image.open(GT_Str[0])
b = image.getcolors()
b.sort(key=takefirst, reverse=True)
print(b)
예제 #8
0
파일: main.py 프로젝트: Spritea/Hotkey
import cv2 as cv
import util
import helpers

out = cv.imread("center_morph.png")
gt = cv.imread("center_gt.png")
label_values = [[0, 0, 0], [255, 255, 255]]
num_classes = len(label_values)
gt = util.reverse_one_hot(util.one_hot_it(gt, label_values))
# out = cv.cvtColor(out, cv.COLOR_GRAY2BGR)
output_image = util.reverse_one_hot(util.one_hot_it(out, label_values))
# out_vis_image = helpers.colour_code_segmentation(output_image, label_values)

accuracy, class_accuracies, prec, rec, f1, iou = util.evaluate_segmentation(
    pred=output_image, label=gt, num_classes=num_classes)

print("precision: %f" % prec)
print("recall: %f" % rec)
print("F1: %f " % f1)
print("mIoU: %f " % iou)
# print("specimen: SAR01-00673")
예제 #9
0
                    (175, 238, 238), (255, 248, 220), (47, 79, 79),
                    (255, 250, 205), (255, 245, 238), (240, 255, 240),
                    (245, 255, 250), (240, 255, 255), (240, 248, 255),
                    (230, 230, 250), (255, 240, 245), (255, 228, 225),
                    (255, 255, 240), (105, 105, 105), (112, 128, 144),
                    (190, 190, 190), (245, 245, 245), (100, 149, 237),
                    (65, 105, 225), (0, 191, 255), (135, 206, 250),
                    (70, 130, 180), (255, 228, 181), (250, 235, 215),
                    (95, 158, 160), (0, 250, 154), (255, 255, 0),
                    (255, 239, 213), (255, 235, 205)]

# label_values_RGB=[(0,0,0),(255,255,255)]
gt = []
pred = []
t = time.time()
GT_precode = util.reverse_one_hot(util.one_hot_it(GT_img, label_values_RGB))
PRED_precode = util.reverse_one_hot(util.one_hot_it(PRED_img,
                                                    label_values_RGB))
gt = GT_precode.flatten()
pred = PRED_precode.flatten()

Acc = accuracy_score(gt, pred)
F1 = f1_score(gt, pred, average=None)
mean_F1 = np.nanmean(F1)
IoU = jaccard_score(gt, pred, average=None)
IoU_format = np.around(100 * IoU, 4)
mean_IoU = np.nanmean(IoU)
tt = time.time() - t
print("class F1")
print(F1)
print("class IoU")
예제 #10
0
파일: precode.py 프로젝트: Spritea/Hotkey
import cv2 as cv
from pathlib import Path
import natsort
import util
from tqdm import tqdm

def load_image(path):
    image = cv.cvtColor(cv.imread(path, 1), cv.COLOR_BGR2RGB)
    return image

GT_Path = Path("C://Users/think\Desktop/train_samesize\clean_data/test_gt")
GT_File = natsort.natsorted(list(GT_Path.glob("*.png")), alg=natsort.PATH)
GT_Str = []
for i in GT_File:
    GT_Str.append(str(i))

out_prefix="C:\\Users\\think\Desktop\\train_samesize\clean_data\\test_gt_precode\\"
# label_values_GID_9 = [[0,0,0], [0,0,200],[250,150,150],[250,200,0],[0,200,0],[200,0,200],[200,0,0],[250,0,150],[200,150,150]]
# label_values_GID_16=[[0,0,0],[0,200,0],[150,250,0],[150,200,150],[200,0,200],[150,0,250],[150,150,250],[250,200,0],[200,200,0],[200,0,0],[250,0,150],[200,150,150],[250,150,150],[0,0,200],[0,150,200],[0,200,250]]
# label_values_GID_8 = [[0,0,0], [150,250,0],[0,200,0],[200,0,200],[250,200,0],[200,0,0],[250,150,150],[0,0,200]]
# label_values_RGB_SCPA_WC = [[0,0,0], [128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128]]
label_values_binary=[[0,0,0],[255,255,255]]
for k in tqdm(range(len(GT_Str))):
    gt=load_image(GT_Str[k])
    out=util.reverse_one_hot(util.one_hot_it(gt,label_values_binary))
    out_str=out_prefix+Path(GT_Str[k]).name
    cv.imwrite(out_str,out)
    # print("kk")

예제 #11
0
    for j in range(id_start, id_stop):
        pic_small.append(
            cv.cvtColor(cv.imread(IMG_Str[j], cv.IMREAD_COLOR),
                        cv.COLOR_BGR2RGB))
    id_start += one_large_contain_small
    out_path_prefix = "SCPA_WC/large/color/frrnb/"
    out_name = str(k) + '_pred.png'
    combine_one(pic_small, out_name, width, height)


#以下是18_preprocee里precode.py直接复制的
def load_image(path):
    image = cv.cvtColor(cv.imread(path, 1), cv.COLOR_BGR2RGB)
    return image


GT_Path = Path("../16_find_compact/SCPA_WC/large/color/frrnb")
GT_File = natsort.natsorted(list(GT_Path.glob("*.png")), alg=natsort.PATH)
GT_Str = []
for i in GT_File:
    GT_Str.append(str(i))

out_prefix = "../16_find_compact/SCPA_WC/large/precode/frrnb/"
label_values_RGB_SCPA_WC = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
                            [0, 0, 128], [128, 0, 128], [0, 128, 128]]
for k in tqdm(range(len(GT_Str))):
    gt = load_image(GT_Str[k])
    out = util.reverse_one_hot(util.one_hot_it(gt, label_values_RGB_SCPA_WC))
    out_str = out_prefix + Path(GT_Str[k]).name
    cv.imwrite(out_str, out)
    # print("kk")