M通道过采样图滤波器组的多尺度分解 matlab
时间: 2023-11-11 07:07:58 浏览: 69
代码:
```matlab
function [pyr, filter] = m_channel_pyramid(img, levels, filter_size, filter_type)
% M_CHANNEL_PYRAMID: Construct a multi-channel pyramid for a given image.
%
% [PYR, FILTER] = M_CHANNEL_PYRAMID(IMG, LEVELS, FILTER_SIZE, FILTER_TYPE)
%
% - IMG: the input image, with size [h, w, c].
% - LEVELS: the number of pyramid levels.
% - FILTER_SIZE: the size of the filter, e.g., [3, 3].
% - FILTER_TYPE: the type of the filter, e.g., 'gaussian'.
[h, w, c] = size(img);
% Define the filter
filter = cell(c, 1);
for i = 1:c
filter{i} = get_filter(filter_size, filter_type);
end
pyr = cell(levels, c);
for i = 1:c
% Pre-filtering
img(:, :, i) = imfilter(img(:, :, i), filter{i}, 'replicate');
% Multi-scale decomposition
for j = 1:levels
% Downsampling
img = imresize(img, 1/2, 'bilinear');
% Filtering
img(:, :, i) = imfilter(img(:, :, i), filter{i}, 'replicate');
% Save the result
pyr{j, i} = img;
end
end
function filter = get_filter(filter_size, filter_type)
% GET_FILTER: Get the filter for the given size and type.
%
% FILTER = GET_FILTER(FILTER_SIZE, FILTER_TYPE)
if strcmp(filter_type, 'gaussian')
sigma = 0.8;
x = linspace(-filter_size(2)/2, filter_size(2)/2, filter_size(2));
y = linspace(-filter_size(1)/2, filter_size(1)/2, filter_size(1));
[X, Y] = meshgrid(x, y);
filter = exp(-(X.^2 + Y.^2)/(2*sigma^2));
filter = filter / sum(filter(:));
else
error('Unsupported filter type.');
end
```
使用方法:
```matlab
img = imread('lena.png');
img = im2double(img);
levels = 5;
filter_size = [3, 3];
filter_type = 'gaussian';
[pyr, filter] = m_channel_pyramid(img, levels, filter_size, filter_type);
```
阅读全文