Skip to content

Instantly share code, notes, and snippets.

View lettergram's full-sized avatar
🕶️
Loading...

Austin Walters lettergram

🕶️
Loading...
View GitHub Profile
% Create four filters
[hx, hy] = gradient(fspecial('gaussian',[5 5],sigma));
[hx1, hy1] = altOrientFilter1(hx, hy);
[hx2, hy2] = altOrientFilter2(hx, hy);
[hx3, hy3] = altOrientFilter3(hx, hy);
% Run gaussian filters on the image
gx = double(imfilter(img,hx,'replicate', 'conv'));
gy = double(imfilter(img,hy,'replicate', 'conv'));
gx1 = double(imfilter(img,hx1,'replicate', 'conv'));
@lettergram
lettergram / gist:c2d90f2a3cca3514ba69
Last active August 29, 2015 14:17
Applying Derived Gaussian Filters
% Convert an image to double for increased precision
img = double(img);
% Find two derived gaussians with respect to x and y
[hx, hy] = gradient(fspecial('gaussian',[5 5],sigma));
% Run the filters over the image, generating a filtered image
% Leaves x and y images of edges
gx = double(imfilter(img,hx,'replicate', 'conv'));
gy = double(imfilter(img,hy,'replicate', 'conv'));
@lettergram
lettergram / gist:96cad1e293936d5083d5
Created March 14, 2015 03:16
Taking the derivative of gaussian
% Takes the derivative of a 5x5 gaussian, with a sigma
[hx, hy] = gradient(fspecial('gaussian',[5 5],sigma));
@lettergram
lettergram / gist:63cff51e8502d7c9ebf6
Created March 14, 2015 03:17
Lab gradient filter
% Convert an image to the Lab color space
colorTransform = makecform('srgb2lab');
img = applycform(rgbImg, colorTransform);
% Make it double to improve representation
img = double(img);
% Find x and y derivative of a 9x9 gaussian
[hx, hy] = gradient(fspecial('gaussian',[9 9],sigma));
@lettergram
lettergram / pca.m
Last active August 29, 2015 14:17
PCA in matlab
function T = PCA(matrix)
[U,S,V] = svd(matrix * transpose(matrix));
T = U * S
end
@lettergram
lettergram / pca.py
Last active August 29, 2015 14:17
PCA in python
import numpy as np
matrix = np.matrix(matrix) * np.matrix(matrix).transpose()
U,S,V = np.linalg.svd(matrix)
T = U * S
@lettergram
lettergram / PCA.m
Last active August 29, 2015 14:17
PCA Function
% Find score matrix for PCA %
% Outputs score between column s and e %
function W = PCA(matrix, s, e)
[U,S,V] = svd(matrix * transpose(matrix));
T = U * sqrt(S);
T = W(:,s:e);
end
@lettergram
lettergram / seedData_PCA.m
Last active August 29, 2015 14:17
Graph seed dataset PCA
% Graphs components %
file = 'seeds_dataset.csv';
x = load(file);
% SVD matrix
[U,S,V] = svd(x * transpose(x));
% An eigenvalue is the diagonal matrix of S off the SVD component
eV = diag(sqrt(S));
@lettergram
lettergram / PCA-Digit.py
Last active August 29, 2015 14:17
Run PCA on Digits
'''
Full code on: https://github.com/lettergram/PCA
read() obtains every image from training data
http://abel.ee.ucla.edu/cvxopt/_downloads/mnist.py
img = single image from read()
img[0] - id
img[1] - image of digit
'''
# Normalize the image
@lettergram
lettergram / PCA_OCR.py
Last active August 29, 2015 14:17
PCA OCR Identification
u, sigma, test = train(read(), 30)
right = 0.0
total = 0.0
for img in test:
matrix = np.subtract(img[1], np.mean(img[1])) # Center
matrix = np.reshape(matrix, (-1, 1))
covImg = np.dot(matrix, np.reshape(matrix, (1, -1))).T
index = 0;
best = 0.0