图像处理,金字塔分解,示例代码
%% Load image
img=imread('cameraman.tif');
img = double(img) + normrnd(0,5,[256 256]);
%% Gaussian filter
w=1/256*[1 4 6 4 1;
4 16 24 16 4;
6 24 36 24 6;
4 16 24 16 4;
1 4 6 4 1];
%% Laplacian pyramid
%decomposition level
n = 6;
% filtering, subsampling
g{1}=img;
s = [size(g{1},1),size(g{1},2)];
for i=2:n+1
g{i}=imfilter(g{i-1},w,'replicate');
g{i}=g{i}(1:2:size(g{i},1)-1,1:2:size(g{i},2)-1);
s = [s;[size(g{i},1),size(g{i},2)]];
end
%residual image
for i=1:n
l{i}=g{i}-expand(g{i+1},w,s(i,:));
end
%reconstruction
for i=n:-1:1
g{i}=l{i}+expand(g{i+1},w,s(i,:));
end
imshow(g{1},[])
imshow(img,[])
1