Example #1
0
def blockStat(bs, match, indexlist1, indexlist2, image1, image2):
    print("match:", len(match), "\t bs:", bs * 2 + 1)
    try:
        matchtemp = random.sample(match, 500)
    except:
        matchtemp = match
        print("too less sample")
    print("extract 1000 points for calculation")

    possibilityMatrix = gauss.getGuassPossiblityTensor()

    # 正确匹配
    midloss_1 = []
    for i in range(len(matchtemp)):
        mapindex1 = indexlist1[matchtemp[i][0]]
        mapindex2 = indexlist2[matchtemp[i][1]]
        x1, y1 = decompose(mapindex1, image1.shape)
        x2, y2 = decompose(mapindex2, image2.shape)  #

        image1xmin = max(x1 - bs, 0)
        image1ymin = max(y1 - bs, 0)
        image2xmin = max(x2 - bs, 0)
        image2ymin = max(y2 - bs, 0)
        # print(x1,x2,y1,y2)
        # get the block
        temp1 = image1[image1xmin:(x1 + bs), image1ymin:(y1 + bs)]
        temp2 = image2[image2xmin:(x2 + bs), image2ymin:(y2 + bs)]
        temp1 = temp1.reshape(-1, 3)
        temp2 = temp2.reshape(-1, 3)
        # find the color center => Guass seperate
        ##initialize
        tensor1 = np.zeros((256, 256, 256))
        tensor2 = np.zeros((256, 256, 256))

        ##collection information from two small pixel-blocks
        for j in range(len(temp1)):
            try:
                tensor1 = gauss.blockReplace(tensor1, temp1[j],
                                             possibilityMatrix)
            except:
                print(temp1[j])
        for j in range(len(temp2)):
            try:
                tensor2 = gauss.blockReplace(tensor2, temp2[j],
                                             possibilityMatrix)
            except:
                print(temp2[j])
        tensor1 = tensor1 / (np.sum(tensor1) + 1e-7)
        tensor2 = tensor2 / (np.sum(tensor2) + 1e-7)
        loss = np.linalg.norm(tensor1.flatten() - tensor2.flatten())
        # print("loss",i," ",loss)
        midloss_1.append(loss)
    plt.hist(midloss_1, bins=100)
    plt.ylabel(str(bs * 2 + 1) + 'right match')
    #plt.show()
    plt.savefig(str(bs * 2 + 1) + 'right match.jpg')
    store_vec(str(bs * 2 + 1) + '_right_distribute.txt', midloss_1)
    # select
    # 错误匹配
    midloss_2 = []
    for i in range(len(matchtemp)):
        mapindex1 = indexlist1[matchtemp[i][0]]
        mapindex2 = indexlist2[matchtemp[(i + 3) % len(matchtemp)][1]]
        x1, y1 = decompose(mapindex1, image1.shape)
        x2, y2 = decompose(mapindex2, image2.shape)
        image1xmin = max(x1 - bs, 0)
        image1ymin = max(y1 - bs, 0)
        image2xmin = max(x2 - bs, 0)
        image2ymin = max(y2 - bs, 0)
        # print(x1,x2,y1,y2)
        # get the block
        temp1 = image1[image1xmin:(x1 + bs), image1ymin:(y1 + bs)]
        temp2 = image2[image2xmin:(x2 + bs), image2ymin:(y2 + bs)]
        # find the color center => Guass seperate
        ##initialize
        tensor1 = np.zeros((256, 256, 256))
        tensor2 = np.zeros((256, 256, 256))
        temp1 = temp1.reshape(-1, 3)
        temp2 = temp2.reshape(-1, 3)
        ##collection information from two small pixel-blocks
        for j in range(len(temp1)):
            try:
                tensor1 = gauss.blockReplace(tensor1, temp1[j],
                                             possibilityMatrix)
            except:
                print(temp1[j])
        for j in range(len(temp2)):
            try:
                tensor2 = gauss.blockReplace(tensor2, temp2[j],
                                             possibilityMatrix)
            except:
                print(temp2[j])
        tensor1 = tensor1 / (np.sum(tensor1) + 1e-7)
        tensor2 = tensor2 / (np.sum(tensor2) + 1e-7)
        loss = np.linalg.norm(tensor1.flatten() - tensor2.flatten())
        # print("loss",i," ",loss)
        midloss_2.append(loss)
    plt.hist(midloss_2, bins=100)
    plt.ylabel(str(bs * 2 + 1) + 'wrong match')
    # plt.show()
    plt.savefig(str(bs * 2 + 1) + 'teeth wrong match.jpg')
    store_vec(str(bs * 2 + 1) + '_wrong_distribute.txt', midloss_2)

    # 计算区分度
    for i in range(99):
        gt = np.percentile(np.array(midloss_1), i + 1)  # right
        wm = np.percentile(np.array(midloss_2), 99 - i)  # wrong
        if (gt - wm > 0):
            print(i)
            # print("hopeing",abs(gt-wm))
            break

    return
Example #2
0
def blockStat(bs,match,indexlist1,indexlist2,image1,image2):
    print("match:", len(match),"\t bs:",bs*2+1)
    j=0############
    try:
        matchtemp = random.sample(match,500)
    except:
        matchtemp = match
        print("too less sample")
    print("extract 1000 points for calculation")

    possibilityMatrix = gauss.getGuassPossiblityTensor()

    # 正确匹配
    colorblocksize = (bs+1)*2
    print("right match")
    midloss_1 = []
    j=0
    for i in range(len(matchtemp)):
        imagefile = "./true_image/"
        mapindex1 = indexlist1[matchtemp[i][0]]
        mapindex2 = indexlist2[matchtemp[i][1]]
        x1, y1 = decompose(mapindex1, image1.shape)
        x2, y2 = decompose(mapindex2, image2.shape)  #
        image1xmin = max(x1 - bs, 0)
        image1ymin = max(y1 - bs, 0)
        image2xmin = max(x2 - bs, 0)
        image2ymin = max(y2 - bs, 0)
    
        # print(x1,x2,y1,y2)
        # get the block
        temp1 = image1[image1xmin:(x1 + bs+2), image1ymin:(y1 + bs + 2)]
        temp2 = image2[image2xmin:(x2 + bs+2), image2ymin:(y2 + bs + 2)]
        if (temp1.shape ==(colorblocksize,colorblocksize,3))&(temp2.shape ==(colorblocksize,colorblocksize,3)):
            save_image(imagefile+str(j)+"_1.jpg",temp1)
            save_image(imagefile+str(j)+"_2.jpg",temp2)
            j=j+1
        else:
            print("temp1.shape:",temp1.shape)
            print("temp2.shape:",temp2.shape)
    print("generate "+str(j))
    print("wrong match:")
    j=0
    for i in range(len(matchtemp)):
        imagefile = "./wrong_image/"
        mapindex1 = indexlist1[matchtemp[i][0]]
        mapindex2 = indexlist2[matchtemp[(i + 3) % len(matchtemp)][1]]
        x1, y1 = decompose(mapindex1, image1.shape)
        x2, y2 = decompose(mapindex2, image2.shape)
        image1xmin = max(x1 - bs, 0)
        image1ymin = max(y1 - bs, 0)
        image2xmin = max(x2 - bs, 0)
        image2ymin = max(y2 - bs, 0)
        temp1 = image1[image1xmin:(x1 + bs+2), image1ymin:(y1 + bs + 2)]
        temp2 = image2[image2xmin:(x2 + bs+2), image2ymin:(y2 + bs + 2)]
        if (temp1.shape ==(colorblocksize,colorblocksize,3))&(temp2.shape ==(colorblocksize,colorblocksize,3)):
            save_image(imagefile+str(j)+"_1.jpg",temp1)
            save_image(imagefile+str(j)+"_2.jpg",temp2)
            j=j+1
        else:
            print("temp1.shape:",temp1.shape)
            print("temp2.shape:",temp2.shape)
    print("generate "+str(j))
    print("end")
    return