Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import code
- import numpy as np
- import math
- from skimage.transform import ProjectiveTransform
- from sklearn.metrics import roc_auc_score
- from skimage import io
- import scipy
- import matplotlib.pyplot as plt
- import random
- from random import randint
- import scipy.ndimage.filters as fi
- import scipy.stats as st
- BINS = 15
- SIGMA = 1.5
- def gkern(kernlen=21, nsig=2):
- interval = (2*nsig+1.)/(kernlen)
- x = np.linspace(-nsig-interval/2., nsig+interval/2., kernlen+1)
- kern1d = np.diff(st.norm.cdf(x))
- kernel_raw = np.sqrt(np.outer(kern1d, kern1d))
- kernel = kernel_raw/kernel_raw.sum()
- return kernel
- def extract(image, keypoints):
- image = image / np.max(image)
- image = image * 255
- image = image.astype(np.uint8)
- tab = []
- imgs = []
- angles = []
- for point in keypoints:
- img = get_img_around(image, point)
- tab.append(descriptor(img))
- imgs.append(img)
- return tab
- def get_img_around(image, point):
- x, y = point
- img = image[x-31:x+32, y-31:y+32]
- return img
- def split_image(image):
- imgs = []
- for i in range(4, 60, 8):
- for j in range(4, 60, 8):
- imgs.append(image[i:i+8, j:j+8])
- return imgs
- def normalize(img):
- img = img - np.min(img)
- img = (img / float(np.max(img))) * 255
- return img
- def descriptor(img):
- desc = []
- img = fi.gaussian_filter(img, sigma=SIGMA)
- img = normalize(img)
- for i in split_image(img):
- desc.append(small_descriptor(i))
- desc = np.array(desc)
- return desc.flatten()
- def small_descriptor(image):
- image = image.flatten()
- return np.histogram(image, bins = BINS, range = (0, 256))[0]
- def distance(d1, d2):
- return np.sum(np.absolute(d1 - d2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement