特征:点,不变点,线,面,局部区域————>角点特征检测,尺度不变特征检测,边缘检测,多分辨率金字塔和矩特征,斑点特征检测。
高斯金字塔和拉普拉斯金字塔。
%生成高斯滤波器的核
w=fspecial('gaussian',3,0.5)
%进行高斯滤波
g=imfilter(I,w,'conv','symmetric','same')
多分辨率金字塔化一般包括两个步骤:低通滤波平滑——>抽样。调用函数impyramid(),指定reduce或者expand.
% 读入图像
x = imread('qingdao.jpg');
% 执行金字塔分解
% y = step(video.Pyramid, x);
y=impyramid(x,'reduce')
function [ pyr ] = genPyr( img, type, level )
% 功能: 产生图像的高斯金字塔或拉普拉斯金字塔
% 输入:img-灰度图像;
% type-变换的类型:'gauss' or 'laplace';
% level-分解层数
% 输出:PYR-1*LEVEL 元胞数组
pyr = cell(1,level);
pyr{1} = im2double(img);
%%%%%%图像的金字塔化%%%%%%
%计算图像的高斯金字塔
for p = 2:level
pyr{p} = pyr_reduce(pyr{p-1});
end
if strcmp(type,'gauss'), return; end
% 调整图像尺寸
for p = level-1:-1:1
osz = size(pyr{p+1})*2-1;
pyr{p} = pyr{p}(1:osz(1),1:osz(2),:);
end
% 计算图像的拉普拉斯金字塔
for p = 1:level-1
pyr{p} = pyr{p}-pyr_expand(pyr{p+1});
end
end
function [ imgout ] = pyr_reduce( img )
% 功能:计算图像的高斯金字塔
% 输入:img-灰度图像;
% 输出:imgout-分解后的金子塔图像数组
% 生成高斯核
kernelWidth = 5;
cw = .375;
ker1d = [.25-cw/2 .25 cw .25 .25-cw/2];
kernel = kron(ker1d,ker1d');
img = im2double(img);
sz = size(img);
imgout = [];
% 产生图像的高斯金字塔
for p = 1:size(img,3)
img1 = img(:,:,p);
imgFiltered = imfilter(img1,kernel,'replicate','same');
imgout(:,:,p) = imgFiltered(1:2:sz(1),1:2:sz(2));
end
end
function [ imgout ] = pyr_expand( img )
% 功能:图像金字塔扩张
% 输入:img-待扩张的图像
% 输出:imgout-扩张后的图像
kw = 5;
cw = .375;
ker1d = [.25-cw/2 .25 cw .25 .25-cw/2];
kernel = kron(ker1d,ker1d')*4;
ker00 = kernel(1:2:kw,1:2:kw);
ker01 = kernel(1:2:kw,2:2:kw);
ker10 = kernel(2:2:kw,1:2:kw);
ker11 = kernel(2:2:kw,2:2:kw);
img = im2double(img);
sz = size(img(:,:,1));
osz = sz*2-1;
imgout = zeros(osz(1),osz(2),size(img,3));
for p = 1:size(img,3)
img1 = img(:,:,p);
img1ph = padarray(img1,[0 1],'replicate','both');
img1pv = padarray(img1,[1 0],'replicate','both');
img00 = imfilter(img1,ker00,'replicate','same');
img01 = conv2(img1pv,ker01,'valid');
img10 = conv2(img1ph,ker10,'valid');
img11 = conv2(img1,ker11,'valid');
imgout(1:2:osz(1),1:2:osz(2),p) = img00;
imgout(2:2:osz(1),1:2:osz(2),p) = img10;
imgout(1:2:osz(1),2:2:osz(2),p) = img01;
imgout(2:2:osz(1),2:2:osz(2),p) = img11;
end
end
img=imread('')
[pyr]=genPyr(img,'laplace',4)
https://blog.csdn.net/zb1165048017/article/details/51783879