laplacian_pyramid函数拉普拉斯差分matlab代码
时间: 2023-05-27 12:03:54 浏览: 169
以下是laplacian_pyramid函数的拉普拉斯差分Matlab代码:
```
function [lap_pyramid, filter] = laplacian_pyramid(im, levels)
% LAPLACIAN_PYRAMID Function to compute Laplacian pyramid.
% Given an input image and number of levels, returns the Laplacian
% pyramid and the filter used for the pyramid.
%
% Arguments:
% im - Input image
% levels - Number of levels in the pyramid
%
% Returns:
% lap_pyramid - Laplacian pyramid
% filter - Filter used for the pyramid
% Set sigma value for Gaussian filter
sigma = 1.5;
% Generate filter for Gaussian pyramid
filter = fspecial('gaussian', [5 5], sigma);
% Create Gaussian pyramid
gauss_pyramid = cell(levels, 1);
gauss_pyramid{1} = im;
for i = 2:levels
gauss_pyramid{i} = imresize(imfilter(gauss_pyramid{i-1}, filter), 0.5);
end
% Create Laplacian pyramid
lap_pyramid = cell(levels, 1);
lap_pyramid{levels} = gauss_pyramid{levels};
for i = levels-1:-1:1
gauss_exp = imresize(gauss_pyramid{i+1}, size(gauss_pyramid{i}), 'bilinear');
lap_pyramid{i} = gauss_pyramid{i} - gauss_exp;
end
end
```
此代码包含两个输出参数:lap_pyramid和filter。lap_pyramid包含拉普拉斯差分金字塔,filter是用于生成高斯金字塔和拉普拉斯差分金字塔的高斯滤波器。
阅读全文