【matlab】Gauss/Laplace Pyramid

Downsample
1)对图像G_i进行高斯内核卷积
2)将所有偶数行和列去除

Upsample
1)将图像在每个方向扩大为原来的两倍,新增的行和列以0填充
2)放大后的图像卷积,获得 “新增像素”的近似值

这里写图片描述

clear
clc
I = im2double(imread('1.png'));
I=rgb2gray(I);
N = 4; % layer
f = [.05, .25, .4, .25, .05];   % filter
f = f'*f;

G = cell(N,1);
G{1} = I;
for n = 2 : N
  t = imfilter(G{n-1}, f, 'conv', 'same', 'replicate');
  G{n} = t(1:2:end, 1:2:end); % 下采样
end 

L = cell(N,1);
L{N} = G{N};
for n = 1 : N-1
   t = imresize(G{n+1}, 2, 'bicubic');% 双上线性插值
   %t = zeros(2*size(G{n+1}));
   %t(1:2:end, 1:2:end) = G{n+1};
   %t(2:2:end, 2:2:end) = G{n+1};
   %t(1:2:end, 2:2:end) = G{n+1};
   %t(2:2:end, 1:2:end) = G{n+1};% 上采样
   I = imfilter(t, f, 'conv', 'same', 'replicate');
   L{n} = G{n} - I;
end
%figure;
for n = 1 : N
    figure(n);
    %subplot(2,N,n)
    imshow(G{n});
end

for n = 1 : N
    figure(n+N);
    %subplot(2,N,n+N)
    imshow(L{n});
end

参考
图像处理中的高斯金字塔和拉普拉斯金字塔

猜你喜欢

转载自blog.csdn.net/bryant_meng/article/details/80899977