def computeAngles(im): ''' Return an image that holds the angle of the smallest eigenvector of the structure tensor at each pixel. If you have a 3 channel image as input, just set all three channels to be the same value theta.''' out = np.zeros_like(im) tensor = helper.computeTensor(im) for y,x in imIter(tensor): eigenVecs = np.linalg.eigh(tensor[y,x])[1] out[y,x] = min(np.arctan2(eigenVecs[0][0], eigenVecs[0][1]), np.arctan2(eigenVecs[1][0], eigenVecs[1][1])) return out
def computeAngles(im): '''Return an image that holds the angle of the smallest eigenvector of the structure tensor at each pixel. If you have a 3 channel image as input, just set all three channels to be the same value theta.''' thetas = np.zeros(im.shape) tensors = helper.computeTensor(im, sigmaG=3, factor=5) for y in xrange(im.shape[0]): for x in xrange(im.shape[1]): eigvals, eigvecs = np.linalg.eigh(tensors[y, x]) vec = eigvecs[:, np.argmin(eigvals)] thetas[y, x] = np.arctan2(vec[0], vec[1]) + math.pi return thetas
def computeAngles(im): '''Return an image that holds the angle of the smallest eigenvector of the structure tensor at each pixel. If you have a 3 channel image as input, just set all three channels to be the same value theta.''' out = im.copy() tensor = helper.computeTensor(im, 3, 5) for y,x in helper.imIter(tensor): M = tensor[y,x] w, v = np.linalg.eigh( M ) vLarge = v[:, np.argmax(np.abs(w))] angle = np.arctan2( vLarge[1], vLarge[0]) + math.pi out[y,x] = np.array([angle, angle, angle]) return out
def computeAngles(im): '''Return an image that holds the angle of the smallest eigenvector of the structure tensor at each pixel. If you have a 3 channel image as input, just set all three channels to be the same value theta.''' angles = np.zeros(im.shape) # default function gives an error tensor = helper.computeTensor(im, sigmaG=3, factor=5, debug=False) # iterate through whole thing for y in xrange(im.shape[0]): for x in xrange(im.shape[1]): eigenvalues, eigenvectors = np.linalg.eigh(tensor[y, x]) min_vec = eigenvectors[:, np.argmin( eigenvalues)] # indexing syntax wonky! # add pi here to offset negative angles theta = np.arctan2(min_vec[0], min_vec[1]) + math.pi angles[y, x] = theta return angles