def train_lbp(): train_dir = "/home/gast/ImageHashing/face_train/" suffix = ".png" size = 200 train = [] for fn in sorted(os.listdir(train_dir)): if fn.endswith(suffix): rgb = Image.load(train_dir + fn) gray = Image.rgb2gray(rgb) resized = Image.resize(gray,size) img = Image.gray2real(resized) lbps = local_binary_pattern(img,3,24) #print(flatten(lbps)) #print(len(flatten(lbps))) train.append(flatten(lbps)) #print(lbps) pca = PCA(n_components=100) #print(len(train)) #print(len(train[0])) train_np = np.array(train) #print(train_np.shape) pca.fit(train_np) return pca
def train_eigen(): # train_dir = "/home/gast/ImageHashing/face_train/" train_dir = "/home/gast/ImageHashing/FEC/fec_images_autoadjust/" suffix = ".png" size = 200 train = [] for fn in sorted(os.listdir(train_dir)): if fn.endswith(suffix): rgb = Image.load(train_dir + fn) gray = Image.rgb2gray(rgb) resized = Image.resize(gray,size) img = Image.gray2real(resized) #lbps = list(flatten(Lbp.real_hash(img))) img_flat = list(flatten(img)) # print(len(flatten(lbps))) train.append(img_flat) #print(lbps) t = np.array(train) #print("len of train"+str(t.shape)) pca = PCA(n_components=100) pca.fit(train) return pca
def train_lbp(): train_dir = "/home/gast/ImageHashing/face_train/" suffix = ".png" size = 200 train = [] for fn in sorted(os.listdir(train_dir)): if fn.endswith(suffix): rgb = Image.load(train_dir + fn) gray = Image.rgb2gray(rgb) resized = Image.resize(gray,size) img = Image.gray2real(resized) lbps = list(flatten(Lbp.real_hash(img))) # print(len(flatten(lbps))) train.append(lbps) #print(lbps) pca = PCA(n_components=500) pca.fit(train) return pca
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
import numpy as np import matplotlib.pyplot as plt from skimage import data from skimage.feature import match_template import Image needle_rgb = Image.load("90a_scan.png") needle = Image.rgb2gray(needle_rgb) haystack_rgb = Image.load("90a_camera.jpg") haystack = Image.rgb2gray(haystack_rgb) result = match_template(haystack, needle) ij = np.unravel_index(np.argmax(result), result.shape) x, y = ij[::-1] fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 3)) ax1.imshow(needle) ax1.set_axis_off() ax1.set_title('template') ax2.imshow(haystack) ax2.set_axis_off() ax2.set_title('image') # highlight matched region hcoin, wcoin = needle.shape rect = plt.Rectangle((x, y), wcoin, hcoin, edgecolor='r', facecolor='none') ax2.add_patch(rect)