This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Takes the derivative of a 5x5 gaussian, with a sigma | |
[hx, hy] = gradient(fspecial('gaussian',[5 5],sigma)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function T = PCA(matrix) | |
[U,S,V] = svd(matrix * transpose(matrix)); | |
T = U * S | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
matrix = np.matrix(matrix) * np.matrix(matrix).transpose() | |
U,S,V = np.linalg.svd(matrix) | |
T = U * S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer