Skip to content

Instantly share code, notes, and snippets.

@seaslee
seaslee / computer_discs.m
Created October 24, 2012 10:16
the solution to Project Euler 100
function [a,b]=computer_discs()
b1=21;
a1=15;
b2=85+35;
a2=85;
[t1,s1]=computer_st_square(a1,b1);
[t2,s2]=computer_st_square(a2,b2);
@seaslee
seaslee / gist:3945442
Created October 24, 2012 10:50
solution to problem 1 of euler project
function y=ep1(n)
%exhaustive method to computer the sum of multiples of 3 or 5 which is below n
y=0;
for i=1:n-1,
if mod(i,3)==0 || mod(i,5)==0,
y=y+i;
end
end
end
@seaslee
seaslee / ep2.m
Created October 24, 2012 13:08
solution to problem 2 of euler project
function y=ep2(n)
%exhaustive method
a=1;
b=2;
y=2;
c=a+b;
a=b;
b=c;
while c<=n,
@seaslee
seaslee / doOrthProj.m
Created November 7, 2012 14:09
This is simple script to do orthogonal projection in 2-dimesion space
%%This is simple script to do orthogonal projection in 2-dimesion space
function doOrthProj(X,u)
%plot data
x1=X(1,:);
x2=X(2,:);
plot(x1,x2,'r.','MarkerSize',15);
axis([0,round(max(x1))+5,0,round(max(x2))+5]);
xlabel('x1');
@seaslee
seaslee / main.m
Created November 12, 2012 14:05
plot faces and eigenface
close all;
clear;
clc;
X=[];
for i=1:10,
x=imread([int2str(i) '.pgm']);
[w,h]=size(x);
x=reshape(x,w*h,1);
x=double(x);
X=[X x];
@seaslee
seaslee / color.m
Created November 15, 2012 12:19
颜色特征提取,hsv颜色空间,使用颜色直方图,采用非均匀量化
%=============================
%颜色特征提取,hsv颜色空间,使用颜色直方图,采用非均匀量化
%=============================
function fc=color(imgname)
%tic
img=imread(imgname);
hsv=rgb2hsv(img);
%将hsv特征进行非均匀的量化
[height,width,dim]=size(hsv);
len=256;
@seaslee
seaslee / glcm.m
Created November 15, 2012 12:20
纹理特征提取,采用灰度共生矩阵
%==========================
% 纹理特征提取,采用灰度共生矩阵
%==========================
function ft=glcm(imgname)
%tic
img=imread(imgname);
gimg=rgb2gray(img);
% 量化
gl=16;
gimg=gimg/(256/gl);
@seaslee
seaslee / computerUniform.m
Created November 22, 2012 12:02
computer the number of 1->0 and 0->1 transitions in binary string
%use in computer the lbp descriptor
j = bitset(bitshift(i,1,samples),1,bitget(i,samples)) %rotate left; cyclic shift
numt = sum(bitget(bitxor(i,j),1:samples)) %number of 1->0 and
%0->1 transitions
%in binary string
%x is equal to the
%number of 1-bits in
%XOR(x,Rotate left(x))
@seaslee
seaslee / normalize.m
Created December 4, 2012 01:51
A fast and easy way to normalize the matrix
X = X./( ones(size(X)) * diag(sum(abs(X))) ); %L1-normalization
X = X./( ones(size(X)) * sqrt(diag(diag(X'*X))) ); %L2-normalization
@seaslee
seaslee / gist:5088906
Created March 5, 2013 08:55
"mkdir -p" python implementation
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise