matlab自带kpca,求对矩阵进行PCA或者KPCA特征提取的matlab代码
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
這是gabor的代碼
im=imread('G:\pictureROI\why1.jpg');
A=[];B=[];%A,B是空矩陣,初始化,清零。
scale=5; % denote the scale of the gabor wavelet表示gabor小波的尺度
orientation=4; % denote the orientation of the gabor wavelet表示gabor小波的方向
kmax=pi/2; % the highest frequency with the smallest kernel size具有最小內核大小的最高頻率,即頻率上限。
sigma=pi*2; % the parameter :theta 參數θ
mask_size=128; % for every kernel the size is 128*128% this is the size of Gabor mask對于每個內核,大小是128*128%,這是Gabor掩碼的大小
f=sqrt(2); % f is the spacing factor% f是間隔間距因子
sig=sigma*sigma; % the squre of theta %θ的平方
offset=mask_size/2;%偏置/補償/抵消=每個內核大小的一半。
for v=0:(scale-1) %設置循環,外循環5個尺度
for u=0:(orientation-1) %設置循環,內循環4個方向
kv=kmax/f^v; %開始創建gabor核函數
phiu=u*pi/4;
kv_mag=kv*kv;
gabor_kel=zeros(128,128);
for x=0:(mask_size-1)
for y=0:(mask_size-1)
i=x-offset;
j=y-offset;
mag=i*i+j*j;
gabor_kel(x+1,y+1)=kv_mag/sig*exp(-0.5*kv_mag*mag/sig)*(exp(sqrt(-1)*kv*(i*cos(phiu)+j*sin(phiu))-exp(-1.0*sig/2.0)));
end %the gabor kernel gabor核
end
result=abs(fftshift(ifft2((fft2(im)).*fft2(gabor_kel)))); % 與輸入圖像相卷積得到Gabopalm
result_sample=result(1:4:128,1:4:128); %對得到的結果進行下采樣,采樣因子ρ為4
m=mean(result_sample(1:end)); %平均值
s=std(result_sample(1:end)); %標準偏差
result_norm=(result_sample-m)/s; % 對得到的特征向量進行歸一化,下采樣每個值減平均值再除標準偏差得到均值為0方差為1的標準化數據
result_norm=result_norm(1:end); % 變為1*1024的行向量
A=[A result_norm']; % 變為1024*20的gaborface,將result_norm轉置與A拼接。
end
end
output=A; %1024*20的gaborface
總結
以上是生活随笔為你收集整理的matlab自带kpca,求对矩阵进行PCA或者KPCA特征提取的matlab代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 极氪汽车:即日起“极分”可抵扣充电费 1
- 下一篇: Epic喜加一:原价137的《遗迹:灰烬