コード例 #1
0
def blend_last_row_multiple_gradient_thread(i, j, x_max, image_np,
                                            valid_bit_np, ens_prediction,
                                            blended_img, gradient):
    blended_np = np.zeros((image_np.shape[1], image_np.shape[2], 3),
                          dtype='uint8')
    index = i * x_max + j
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)

    if max(ens_prediction[2]) - min(ens_prediction[2]) != 0:
        var_norm = (ens_prediction[2][index] - min(ens_prediction[2])) / (
            max(ens_prediction[2]) - min(ens_prediction[2]))
    else:
        var_norm = ens_prediction[2][index]
    var_mean = ((1 - var_norm) + ens_prediction[0][index]) / 2

    class_idx = ens_prediction[0][index]
    if valid_bit_np[index] == 1:
        color = get_prob_color(gradient[class_idx], ens_prediction[1][index])
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        t_x = j * image_np.shape[2]
        t_y = blended_img.size[1] - image_np.shape[1]
        blended_img.paste(blend(base_img, mask, 0.5, var_mean), (t_x, t_y))
    else:
        color = get_prob_color(gradient[2], 1)
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        t_x = j * image_np.shape[2]
        t_y = blended_img.size[1] - image_np.shape[1]
        blended_img.paste(blend(base_img, mask, 0.5, 1), (t_x, t_y))
コード例 #2
0
def blend_last_std_bigradient(image_np, valid_bit_np, ens_prediction,
                              blended_img, gradient):
    blended_np = np.zeros((image_np.shape[1], image_np.shape[2], 3),
                          dtype='uint8')
    index = -1
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)
    if max(ens_prediction[2]) - min(ens_prediction[2]) != 0:
        var_norm = (ens_prediction[2][index] - min(ens_prediction[2])) / (
            max(ens_prediction[2]) - min(ens_prediction[2]))
    else:
        var_norm = 0
    var_mean = 1 - var_norm

    class_idx = ens_prediction[0][index]
    if valid_bit_np[index] == 1:
        color = get_prob_color_bigradient(gradient[class_idx],
                                          ens_prediction[1][index])
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        t_x = blended_img.size[0] - image_np.shape[2]
        t_y = blended_img.size[1] - image_np.shape[1]
        blended_img.paste(blend(base_img, mask, 0.5, var_mean), (t_x, t_y))
    else:
        color = get_prob_color_bigradient(gradient[2], 1)
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        t_x = blended_img.size[0] - image_np.shape[2]
        t_y = blended_img.size[1] - image_np.shape[1]
        blended_img.paste(blend(base_img, mask, 0.5, 1), (t_x, t_y))
コード例 #3
0
def blend_last_column_thread(i, x_max, image_np, valid_bit_np, ens_prediction,
                             blended_img):
    blended_np = np.zeros((image_np.shape[1], image_np.shape[2], 3),
                          dtype='uint8')
    index = i * x_max + x_max - 1
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)

    var_norm = ens_prediction[2][index]
    if max(ens_prediction[2]) - min(ens_prediction[2]) != 0:
        var_norm = (ens_prediction[2][index] - min(ens_prediction[2])) / (
            max(ens_prediction[2]) - min(ens_prediction[2]))
    var_mean = 1 - var_norm

    if valid_bit_np[index] == 1:
        color = get_class_color(ens_prediction[0][index])
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        t_x = blended_img.size[0] - image_np.shape[2]
        t_y = i * image_np.shape[1]
        blended_img.paste(blend(base_img, mask, 0.5, var_mean), (t_x, t_y))
    else:
        color = get_class_color(2)
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        t_x = blended_img.size[0] - image_np.shape[2]
        t_y = i * image_np.shape[1]
        blended_img.paste(blend(base_img, mask, 0.5, 1), (t_x, t_y))
コード例 #4
0
def blend_thread(i, j, x_max, image_np, valid_bit_np, ens_prediction,
                 blended_img):
    blended_np = np.zeros((image_np.shape[1], image_np.shape[2], 3),
                          dtype='uint8')
    helvetica = ImageFont.truetype(font=font_, size=20)
    text_color = (0, 0, 0)
    d = ImageDraw.Draw(blended_img)
    index = i * x_max + j
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)
    var_norm = ens_prediction[2][index]
    if max(ens_prediction[2]) - min(ens_prediction[2]) != 0:
        var_norm = (ens_prediction[2][index] - min(ens_prediction[2])) / (
            max(ens_prediction[2]) - min(ens_prediction[2]))
    var_mean = 1 - var_norm

    if valid_bit_np[index] == 1:
        color = get_class_color(ens_prediction[0][index])
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        blended_img.paste(blend(base_img, mask, 0.5, var_mean),
                          (j * image_np.shape[2], i * image_np.shape[1]))
        k = 10
        location = (j * image_np.shape[2] + 10, i * image_np.shape[1] + k)
        d.text(location,
               CATEGORIES[ens_prediction[0][index]] +
               " mean: {:.2}".format(ens_prediction[1][index]),
               font=helvetica,
               fill=text_color)
        k = k + 30
        if ens_prediction[0][index] != 2:
            location = (j * image_np.shape[2] + 10, i * image_np.shape[1] + k)
            d.text(location,
                   "H mean: {:.2}".format(ens_prediction[3][index]),
                   font=helvetica,
                   fill=text_color)
            k = k + 30
        if PRINT_STD:
            location = (j * image_np.shape[2] + 10, i * image_np.shape[1] + k)
            d.text(location,
                   "Std: {:.2%}".format(ens_prediction[2][index]),
                   font=helvetica,
                   fill=text_color)
            k = k + 30
        if PRINT_STD:
            location = (j * image_np.shape[2] + 10, i * image_np.shape[1] + k)
            d.text(location,
                   "Norm std: {:.2%}".format(var_norm),
                   font=helvetica,
                   fill=text_color)
    else:
        color = get_class_color(2)
        blended_np[:, :, 0].fill(color[0])
        blended_np[:, :, 1].fill(color[1])
        blended_np[:, :, 2].fill(color[2])
        mask = np_to_pil(blended_np, COLOR)
        blended_img.paste(blend(base_img, mask, 0.5, 1),
                          (j * image_np.shape[2], i * image_np.shape[1]))
コード例 #5
0
def print_std_bigradient():
    image_np = np.zeros((30, 414, 3), "uint8")
    gradient = get_color_std_bigradient()
    lst = gradient[2]
    lst.reverse()

    for i in range(0, 30):
        for j in range(0, 207):
            image_np[i][j][0] = lst[math.floor(j / 3)][0]
            image_np[i][j][1] = lst[math.floor(j / 3)][1]
            image_np[i][j][2] = lst[math.floor(j / 3)][2]
    for i in range(0, 30):
        for j in range(207, 414):
            idx = math.floor((j - 207) / 3)
            x = gradient[0][idx][0]
            y = gradient[0][idx][1]
            z = gradient[0][idx][2]
            image_np[i][j][0] = x
            image_np[i][j][1] = y
            image_np[i][j][2] = z
    image = np_to_pil(image_np, COLOR)
    save_image(image, RESOURCE_FOLDER, "std_bigradient")
コード例 #6
0
def save_last_np(image_np, blended_img):
    index = -1
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)
    t_x = blended_img.size[0] - image_np.shape[2]
    t_y = blended_img.size[1] - image_np.shape[1]
    blended_img.paste(base_img, (t_x, t_y))
コード例 #7
0
def save_last_row_np_thread(i, j, x_max, image_np, blended_img):
    index = i * x_max + j
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)
    t_x = j * image_np.shape[2]
    t_y = blended_img.size[1] - image_np.shape[1]
    blended_img.paste(base_img, (t_x, t_y))
コード例 #8
0
def save_last_column_np_thread(i, x_max, image_np, blended_img):
    index = i * x_max + x_max - 1
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)
    t_x = blended_img.size[0] - image_np.shape[2]
    t_y = i * image_np.shape[1]
    blended_img.paste(base_img, (t_x, t_y))
コード例 #9
0
def print_std_gradient():
    gradient = get_color_std_gradient()
    image = np_to_pil(gradient, COLOR)
    save_image(image, RESOURCE_FOLDER, "std_gradient")
コード例 #10
0
def save_np_thread(i, j, x_max, image_np, blended_img):
    index = i * x_max + j
    base_img = np_to_pil(image_np[index][:][:][:], COLOR)
    blended_img.paste(base_img, (j * image_np.shape[2], i * image_np.shape[1]))