-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_hanningPlaid.m
68 lines (56 loc) · 2.2 KB
/
image_hanningPlaid.m
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
function imageBitmap = image_hanningPlaid(imSize,degSize,freq,contrast,center,orientation,L,winSize,phase,antiAliasing)
%function imageBitmap = image_hanningGrating(imSize,degSize,freq,contrast,center,orientation,L,winSize,phase,antiAliasing)
% creates a sinwave plaid with the given parameters, you may pass a vector
% of two numbers in freq, contrast, orientation, and phase if you want to
% specify assymetric plaids, otherwise the values are mirrored
global useGPU
if isempty(useGPU)
useGPU = false;
end
if ~exist('antiAliasing','var') || isempty(antiAliasing)
antiAliasing = 4;
end
imSize = antiAliasing*imSize;
if useGPU
imageBitmap = L.*gpuArray.ones(imSize);
else
imageBitmap = L.*ones(imSize);
end
if ~all(contrast==0)
if numel(freq) == 1
freq = [freq,freq];
end
if numel(contrast) == 1
contrast = [contrast,contrast];
end
if numel(orientation) == 1
orientation = [pi/2+orientation,pi/2-orientation];
end
if numel(phase) == 1
phase = [phase,phase];
end
assert(numel(freq)==numel(contrast) && numel(contrast) == numel(orientation) && numel(orientation) == numel(phase), 'Number of Contrasts, frequencies orientations and phases for the plaids should be equal or all in 1-2')
if useGPU
x = gpuArray.linspace(0, degSize(2),imSize(2))-center(2);
y = gpuArray.linspace(0, degSize(1),imSize(1))-center(1);
else
x = linspace(0, degSize(2),imSize(2))-center(2);
y = linspace(0, degSize(1),imSize(1))-center(1);
end
[xx,yy] = meshgrid(x,y');
for iPlaid = 1:length(contrast)
xRot = sin(orientation(iPlaid))*yy+cos(orientation(iPlaid))*xx;
yRot = cos(orientation(iPlaid))*yy-sin(orientation(iPlaid))*xx;
xRot1 = xRot./winSize(1);
yRot1 = yRot./winSize(2);
r2 = xRot1.^2+yRot1.^2;
window = (r2<1).*(0.5+0.5*cos(pi*(sqrt(r2))));
if freq(iPlaid)~=0
grating = sin(2*pi*xRot*freq(iPlaid)+phase(iPlaid));
else
grating = 1+0*xRot;
end
imageBitmap= imageBitmap + contrast(iPlaid)*L.*window.*grating;
end
end
imageBitmap = imresize(imageBitmap,1/antiAliasing);