1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
function y = load_image(type, n)
% load_image - load benchmark images.
%
% y = load_image(type, n);
%
% type can be
% 'chessboard1', 'boat', 'lena', 'goldhill', 'mandrill', 'maurice'.
%
% Copyright (c) 2004 Gabriel Peyr
if nargin<2
n = 512;
end
type = lower(type);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for the line, can be vertical / horizontal / diagonal / qcq
if strcmp(type, 'line')
eta = 0.1; % translation
gamma = 1/sqrt(2); % slope
elseif 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
r = 0.6; % radius
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch type
case 'chessboard1'
x = -1:2/(n-1):1;
[Y,X] = meshgrid(x,x);
y = (2*(Y>=0)-1).*(2*(X>=0)-1);
case 'square'
x = -1:2/(n-1):1;
[Y,X] = meshgrid(x,x);
y = max( abs(X),abs(Y) )<r;
case {'line', 'line_vertical', 'line_horizontal', 'line_diagonal'}
x = 0:1/(n-1):1;
X = x'*ones(1,n);
if gamma~=Inf
y = (X-eta) - gamma*X' < 0;
else
y = (X'-eta) < 0;
end
case 'disk'
radius = 0.35;
x = 0:1/(n-1):1;
[Y,X] = meshgrid(x,x);
center = [0.5, 0.5]; % center of the circle
y = (X-center(1)).^2 + (Y-center(2)).^2 < radius^2;
case 'quarterdisk'
radius = 0.95;
x = 0:1/(n-1):1;
[Y,X] = meshgrid(x,x);
center = -[0.1, 0.1]; % center of the circle
y = (X-center(1)).^2 + (Y-center(2)).^2 < radius^2;
case '3contours'
r1 = 1.3;
ct1 = [-1, 1];
r2 = 0.8;
ct2 = [0, 0];
x = 0:1/(n-1):1;
[Y,X] = meshgrid(x,x);
f1 = (X-ct1(1)).^2 + (Y-ct1(2)).^2 < r1^2;
f2 = (X-ct2(1)).^2 + (Y-ct2(2)).^2 < r2^2;
y = f1 + 0.5*f2.*(1-f1);
otherwise
y = imread( [type, '.jpg'] );
y = double(y);
if n~=size(y, 1)
y = image_resize(y,n,n);
end
end
y = double(y); |
Partager