www.pudn.com > SPIHT_bandelet.rar > load_image.m


function M = load_image(type, n, options) 
 
% load_image - load benchmark images. 
% 
%   M = load_image(name, n, options); 
% 
%   name can be: 
%   Synthetic images: 
%       'chessboard1', 'chessboard', 'square', 'disk', 'quaterdisk', '3contours', 'line', 
%       'line_vertical', 'line_horizontal', 'line_diagonal', 'line_circle', 
%       'parabola', 'sin', 'phantom' 
%   Natural images: 
%       'boat', 'lena', 'goldhill', 'mandrill', 'maurice', 'polygons_blurred'. 
%    
%   Copyright (c) 2004 Gabriel Peyré 
 
if nargin<2 
    n = 512; 
end 
options.null = 0; 
 
type = lower(type); 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% parameters for geometric objects 
eta = 0.1;              % translation 
gamma = 1/sqrt(2);      % slope 
if isfield( options, 'eta' ) 
    eta = options.eta; 
end 
if isfield( options, 'gamma' ) 
    eta = options.gamma; 
end 
if isfield( options, 'radius' ) 
    radius = options.radius; 
end 
if isfield( options, 'center' ) 
    center = options.center; 
end 
if isfield( options, 'center1' ) 
    center1 = options.center1; 
end 
 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% for the line, can be vertical / horizontal / diagonal / any 
if strcmp(type, 'line_vertical') 
    eta = 0.5;              % translation 
    gamma = 0;      % slope 
elseif strcmp(type, 'line_horizontal') 
    eta = 0.5;              % translation 
    gamma = Inf;      % slope 
elseif strcmp(type, 'line_diagonal') 
    eta = 0;              % translation 
    gamma = 1;      % slope 
end 
 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% for some blurring 
sigma = 0; 
if isfield(options, 'sigma') 
    sigma = options.sigma; 
end 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
switch type 
    case 'chessboard1' 
        x = -1:2/(n-1):1; 
        [Y,X] = meshgrid(x,x); 
        M = (2*(Y>=0)-1).*(2*(X>=0)-1); 
         
    case 'chessboard' 
        if ~isfield( options, 'width' ) 
            width = round(n/16); 
        else 
            width = options.width; 
        end 
        [Y,X] = meshgrid(0:n-1,0:n-1); 
        M = mod( floor(X/width)+floor(Y/width), 2 ) == 0; 
         
    case 'square' 
        if ~isfield( options, 'radius' ) 
            radius = 0.6; 
        end 
        x = -1:2/(n-1):1; 
        [Y,X] = meshgrid(x,x); 
        M = max( abs(X),abs(Y) )gamma*Y+0.25 ); 
        M2 = X.^2 + Y.^2 < 0.6^2; 
        M = 20 + max(0.5*M1,M2) * 216; 
         
    case 'parabola' 
         
        % curvature 
        if isfield(options, 'c') 
            c = options.c; 
        else 
            c = 0.1; 
        end 
        % angle 
        if isfield(options, 'theta'); 
            theta = options.theta; 
        else 
            theta = pi/sqrt(2); 
        end 
        x = -0.5:1/(n-1):0.5; 
        [Y,X] = meshgrid(x,x); 
        Xs = X*cos(theta) + Y*sin(theta); 
        Y =-X*sin(theta) + Y*cos(theta); X = Xs; 
        M = Y>c*X.^2;  
         
    case 'sin' 
         
        [Y,X] = meshgrid(-1:2/(n-1):1, -1:2/(n-1):1); 
        M = Y >= 0.6*cos(pi*X); 
        M = double(M); 
 
    case 'phantom' 
         
        M = phantom(n); 
         
    case 'periodic_bumps' 
         
        if isfield(options, 'nbr_periods') 
            nbr_periods = options.nbr_periods; 
        else 
            nbr_periods = 8; 
        end 
        if isfield(options, 'theta') 
            theta = options.theta; 
        else 
            theta = 1/sqrt(2); 
        end 
        if isfield(options, 'skew') 
            skew = options.skew; 
        else 
            skew = 1/sqrt(2); 
        end 
         
        A = [cos(theta), -sin(theta); sin(theta), cos(theta)]; 
        B = [1 skew; 0 1]; 
        T = B*A; 
        x = (0:n-1)*2*pi*nbr_periods/(n-1); 
        [Y,X] = meshgrid(x,x); 
        pos = [X(:)'; Y(:)']; 
        pos = T*pos; 
        X = reshape(pos(1,:), n,n); 
        Y = reshape(pos(2,:), n,n); 
        M = cos(X).*sin(Y);       
         
    otherwise 
        ext = {'gif', 'png', 'jpg', 'bmp', 'tiff', 'pgm'}; 
        for i=1:length(ext) 
            name = [type '.' ext{i}]; 
            if( exist(name) ) 
                M = imread( name ); 
                M = double(M); 
                if n~=size(M, 1) && nargin>=2 
                    M = image_resize(M,n,n); 
                end 
                return; 
            end 
        end 
        error( ['Image ' type ' does not exists.'] ); 
end 
 
M = double(M); 
 
if sigma>0 
    h = ones(sigma); 
    h = conv2(h,h); 
    h = h/sum(h(:)); 
    M = conv2(M, h, 'same'); 
end 
 
M = rescale(M) * 256;