Example #1
0
def compute_hash(filename):        
    re = 64
    if args.r != None:
        re = args.r[0]
    rgb = Image.load(filename)
    gray = Image.rgb2gray(rgb)
    gray_pp = gray
    if(args.pp != None and args.pp[0] == 'gb'):
        gray_pp = Image.gauss_blur(gray,2)
    if(args.pp != None and args.pp[0] == 'tt'):
        gray_pp = tt_pipeline(gray)
    resized = Image.resize(gray_pp,re)
    img = Image.gray2real(resized)
    hash_result = []
    if(args.cm != None and args.cm[0] == "ham"):
        if(args.hm != None):
            if args.hm[0] == "ah":
                img = Image.resize(img,8)
                hash_result = Average.bin_hash(img)
            if args.hm[0] == "dh":
                img = Image.resize2(img,9,8)
                hash_result = Difference.bin_hash(img)
            if args.hm[0] == "dct":
                hash_result = Dct.bin_hash(img,8,8)
            if args.hm[0] == "zh":
                hash_result = Zernike.bin_hash(img,0,8)
            if args.hm[0] == "pzh":
                hash_result = PseudoZernike.bin_hash(img,0,11)
            if args.hm[0] == "rash":
                print("Radon Hash can only output reals")
            if args.hm[0] == "wu":
                input_wu = Image.resize(gray,384)
                hash_result = Wu.bin_hash(input_wu)
    else:
        if(args.hm != None):
            if args.hm[0] == "ah":
                img = Image.resize(img,8)
                hash_result = Average.real_hash(img)
            if args.hm[0] == "dh":
                img = Image.resize2(img,9,8)
                hash_result = Difference.real_hash(img)
            if args.hm[0] == "dct":
                #img1 = exposure.equalize_hist(img)
                hash_result = Dct.real_hash(img,8,8)
            if args.hm[0] == "zh":
                hash_result = Zernike.real_hash(img,0,12)
            if args.hm[0] == "pzh":
                hash_result = PseudoZernike.real_hash(img,0,11)
            if args.hm[0] == "lbp":                
                hash_result = Lbp.real_hash(img)
            if args.hm[0] == "lbp1":
                # im = Image.resize2(gray,220,220)
                im = Image.resize(gray,220)
                im2 = Image.gray2real(im)
                img_blur = Image.gauss_blur(im2,2)
                hash_result = Lbp.real_hash(img_blur)
                #hash_result = Lbp.bin_hash(img_blur)
            #if args.hm[0] == "lbp_pca":
            #    pcad = pickle.load(open("lbp_pca_train.p", "rb" ))
            #    hash_result = Lbp.pca_hash(img,pcad)
                #print(len(hash_result))
            #if args.hm[0] == "eigen":
            #    model = pickle.load(open("eigen_model.p", "rb" ))
            #    hash_result = eigen.transform_eigen(img,model)
            if args.hm[0] == "fft":
                hash_result = Fft.fft_hash(img)
            if args.hm[0] == "rash":
                img = Image.resize(img,63)
                hash_result = Radon.real_hash(img)
    # default
    if hash_result == []:
        print("default")
        hash_result = Dct.real_hash(img,8,8)
    return hash_result