图像提取基于matlab PCA-CSIFT feature图像特征提取含Matlab源码 1174期
Posted 紫极神光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像提取基于matlab PCA-CSIFT feature图像特征提取含Matlab源码 1174期相关的知识,希望对你有一定的参考价值。
一、简介
二、源代码
%%initial image and create input H image.
clear;
clc
img=imread('test.png');
row=256;
colum=256;
img=imresize(img,[row,colum]);
transfer_matrix=[0.06,0.63,0.27;0.3,0.04,-0.35;0.34,-0.6,0.17];
R=img(:,:,1);
G=img(:,:,2);
B=img(:,:,3);
e=transfer_matrix(1,1)*R+transfer_matrix(1,2)*G+transfer_matrix(1,3)*B;
e1=transfer_matrix(2,1)*R+transfer_matrix(2,2)*G+transfer_matrix(2,3)*B;
e2=transfer_matrix(3,1)*R+transfer_matrix(3,2)*G+transfer_matrix(3,3)*B;
H=(double(e1)./double(e2));
origin=img;
img=H;
[m,n]=size(img);
%% Scale-Space Extrema Detection
% original sigma and the number of actave can be modified.
sigma=1.6;
octave=3;%6*sigma*k^(octave*level)<=min(m,n)/(2^(octave-2))
level=5;
k=2^(1/level);
D=cell(1,octave);
for i=1:octave
D(i)=mat2cell(zeros(row*2^(2-i)+2,colum*2^(2-i)+2,level),row*2^(2-i)+2,colum*2^(2-i)+2,level);
end
% first image in first octave is created by interpolating the original one.
temp_img=img(1:1/2:m,1:1/2:n);
temp_img=padarray(temp_img,[1,1],'pre');
temp_img=padarray(temp_img,[1,1],'replicate');
%create the DoG pyramid.
for i=1:octave
temp_D=D{i};
sigma=sigma*sqrt(2)^(i-1);
for j=1:level
p=(level)*(i-1);
figure(1);
subplot(octave,level,p+j);
f=fspecial('gaussian',[1,floor(6*sigma*k^(p+j-1))],sigma*k^(p+j-1));
L1=temp_img;
if(i==1&&j==1)
L2=conv2(temp_img,f,'same');
L2=conv2(L2,f','same');
temp_D(:,:,j)=L2-L1;
imshow(uint8(255 * mat2gray(temp_D(:,:,j))));
L1=L2;
else
L2=conv2(temp_img,f,'same');
L2=conv2(L2,f','same');
temp_D(:,:,j)=L2-L1;
L1=L2;
if(j==level)
temp_img=L1(2:end-1,2:end-1);
end
imshow(uint8(255 * mat2gray(temp_D(:,:,j))));
end
end
D{i}=temp_D;
temp_img=temp_img(1:2:end,1:2:end);
temp_img=padarray(temp_img,[1,1],'replicate');
end
%% Keypoint Localistaion
% search each pixel in the DoG map to find the extreme point
interval=level-1;
extrema=[];
for i=1:octave
[m,n,~]=size(D{i});
m=m-2;
n=n-2;
volume=m*n/(4^(i-1));
for k=2:interval
for j=1:volume
% starter=D(ceil(i/m)+1,mod(i-1,n)+1+1,j);
sub=D{i}(ceil(j/m):ceil(j/m)+2,mod(j-1,n)+1:mod(j-1,n)+3,k-1:k+1);
large=max(max(max(sub)));
little=min(min(min(sub)));
if(large==D{i}(ceil(j/m)+1,mod(j-1,n)+1+1,k))
temp=[i,k,j,1];
extrema=[extrema,temp];
end
if(little==D{i}(ceil(j/m)+1,mod(j-1,n)+1+1,k))
temp=[i,k,j,-1];
extrema=[extrema,temp];
end
end
end
end
%% accurate keypoint localization
%eliminate the point with low contrast or poorly localised on an edge
% x:|,y:-- x is for vertial and y is for horizontal
% value comes from the paper.
threhold=0.03;
r=10;
extr_volume=length(extrema)/4;
[m,n]=size(img);
for i=1:extr_volume
x=floor((extrema(4*(i-1)+3)-1)/(m/(2^(extrema(4*(i-1)+1)-2))))+1;
y=mod((extrema(4*(i-1)+3)-1),n/(2^(extrema(4*(i-1)+1)-2)))+1;
rx=x+1;
ry=y+1;
rz=extrema(4*(i-1)+2);
z=D{extrema(4*(i-1)+1)}(rx,ry,rz);
if(abs(z)<threhold)
extrema(4*(i-1)+4)=0;
else
Dxx=D{extrema(4*(i-1)+1)}(rx-1,ry,rz)+D{extrema(4*(i-1)+1)}(rx+1,ry,rz)-2*D{extrema(4*(i-1)+1)}(rx,ry,rz);
Dyy=D{extrema(4*(i-1)+1)}(rx,ry-1,rz)+D{extrema(4*(i-1)+1)}(rx,ry+1,rz)-2*D{extrema(4*(i-1)+1)}(rx,ry,rz);
Dxy=D{extrema(4*(i-1)+1)}(rx-1,ry-1,rz)+D{extrema(4*(i-1)+1)}(rx+1,ry+1,rz)-D{extrema(4*(i-1)+1)}(rx-1,ry+1,rz)-D{extrema(4*(i-1)+1)}(rx+1,ry-1,rz);
deter=Dxx*Dyy-Dxy*Dxy;
R=(Dxx+Dyy)/deter;
R_threshold=(r+1)^2/r;
if(deter<0||R>R_threshold)
extrema(4*(i-1)+4)=0;
end
end
end
flag=[];
for i=1:1:extr_volume
if(extrema(4*(i-1)+4)==0)
flag=[flag,(4*(i-1)+1:4*i)];
end
end
extrema(flag)=[];
extr_volume=length(extrema)/4;
% eliminate the points on the image edge.
flag=[];
for i=1:extr_volume
x=floor((extrema(4*(i-1)+3)-1)/(m/(2^(extrema(4*(i-1)+1)-2))))+1;
y=mod((extrema(4*(i-1)+3)-1),n/(2^(extrema(4*(i-1)+1)-2)))+1;
if(x==1||x==m/(2^(extrema(4*(i-1)+1)-2))||y==1||y==n/(2^(extrema(4*(i-1)+1)-2)))
flag=[flag,(4*(i-1)+1:4*i)];
end
end
extrema(flag)=[];
extr_volume=length(extrema)/4;
figure(2)
imshow(origin);
for i=1:extr_volume
x=floor((extrema(4*(i-1)+3)-1)/(m/(2^(extrema(4*(i-1)+1)-2))))+1;
y=mod((extrema(4*(i-1)+3)-1),n/(2^(extrema(4*(i-1)+1)-2)))+1;
rx=x/2^(octave-1-extrema(4*(i-1)+1));
ry=y/2^(octave-1-extrema(4*(i-1)+1));
text图像特征提取基于matlab脉冲耦合神经网络(PCNN)图像特征提取含Matlab源码 1868期
MATLAB教程案例45基于双目视觉的图像深度信息提取算法matlab仿真
图像提取基于matlab DNA编解码多尺度形态学提取眼前节组织含Matlab源码 1191期