wavesyn.m

来自「基于小波变换的特征检索算法」· M 代码 · 共 61 行

M
61
字号
function [syn, low, im] = wavesyn(file, nlevels, wname)
% WAVESYN Wavelet-based texture synthesis
%
% Input:
%	file: 	filename of the input texture image
%		Support all formats by imread
%	nlevels: number of wavelet decomposition levels
%	wname: 	string of wavelet name
%
% Output:
%	syn:	synthetic texture image (low + synthetic details)
%	low:	texture image from low resolution
%
% See also: WAVEFEAT

% Read in the image
if ischar(file)
    im = imread(file);
	
    % If image is true color, convert it into an intensity image
    if ndims(im) == 3
        im = double(rgb2gray(im));
    else
        im = double(im);
    end
else
    % Input is a matrix
    im = double(file);
end    

% Standard wavelet decomposition
[c, s] = wavedec2(im, nlevels, wname);

nbands = 3 * nlevels;

% Options for use in GGMLE
options = optimset('display', 'off', 'TolX', 1e-6, 'MaxIter', 10);

for b = 1:nbands
    ind = sbind2(s, b);
    band = c(ind);
    
    % Features from model parameters        
    % Maximum likelihood estimation
    [alpha, beta] = ggmle(band, options);

    % Generate subband coefficients based on model parameters
    r = ggrnd(alpha, beta, 1, length(band));
    
    % Update wavelet coefficients
    c(ind) = r;
end

% Reconstruct with generated detail coefficients
syn = waverec2(c, s, wname);

% And also recontructed approximation at coarset level
if nargout > 1
    low = wrcoef2('a', c, s, wname, nlevels);%computes the matrix of reconstructed approximation coefficients of nlevels, based on the wavelet decomposition structure[c,s]
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?