-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateBinocularWallpaperCopy.m
137 lines (108 loc) · 6.95 KB
/
GenerateBinocularWallpaperCopy.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
function GenerateBinocularWallpaperCopy(ress,bgcolor)
% Generates a wallpaper that can be used for checking/adjusting locations binocular(dual) displays
% function GenerateBinocularWallpaperCopy(ress,:bgcolor)
% (: is optional)
%
% This function generates a special wallpaper using the images stored in ~/BinocularDisplayChecker/pngs.
% In binocular stimulus (e.g. stereograms, or binocular rivalry) presentation, we may present left and right
% eye images onto two displays separately (and we may also use an additional display for a console).
% In such a situation, a strict positional adjustment of the two displays will be necessary for accurate
% binocular fusion and precise measurements. The wallpaper(s) generated by this function can support these
% adjustment by presenting guidelines on the screen.
%
% [example]
% >> GenerateBinocularWallpaperCopy([1920,1200;1920,1080;1920,1080],[127,127,127]);
% >> GenerateBinocularWallpaperCopy([0,0;1920,1080;1920,1080],[127,127,127]);
%
% [input]
% ress: display resolutions, a 3 x 2 matrix.
% [width_display_1, height_display_1; width_display_2, height_display_2; width_display_3, height_display_3]
% here, display 1 is for a console, display 2 is for presenting left-eye image, and display 2 is for
% presenting right-eye image.
% e.g. ress=[1920,1200; 1920, 1080; 1920, 1080].
% NOTE 1: if you don't use the console display (display 1) or the right-eye-image (display 3),
% please set 0 to ress of these displays.
% e.g. ress=[0,0; 1920, 1080; 1920, 1080]; or ress=[0,0;0,0;1920,1080];
% NOTE 2: currently, only specific pairs of the display resolutions listed below are available
% since the images are prepared in advance. if you need different resolutions, please generate
% PNG wallpaper materials in advance using some graphics software.
% available: [1024, 768], [1280,1024], [1920,1080], [1920,1200], and [2560, 1440] (width,height).
% bgcolor : (optional) background to be used on the console display (display 1)
% bgcolor=[127,127,127] by default.
%
% [output]
% no output variable, the generated wallpaper image is saved in the current directory as
% wallpaper_[1|2|3]_display*.png
%
%
% Created : "2016-01-17 14:57:53 ban"
% Last Update: "2021-06-17 00:19:14 ban"
%% check the input variables
if nargin<1 || isempty(ress), help(mfilename()); return; end
if nargin<2 || isempty(bgcolor), bgcolor=[127,127,127]; end
%% processing -- generating the required background (wellpaper) especially for binocular display location adjustments.
% get the maximum vertical display resolution.
max_res_v=ress(1,2);
for ii=2:1:size(ress,1)
if ress(ii,2)>max_res_v, max_res_v=ress(ii,2); end
end
% initialize wallpaper image
wimg=uint8( repmat(reshape(bgcolor,[1,1,3]),[max_res_v,sum(ress(:,1)),1]) );
% generating the wallpaper for binocular display location adjustment.
% only disp 1 is used
if ress(1,1)~=0 && ress(2,1)==0 && ress(3,1)==0
fprintf('processing display 1 alone with resolution: [width, height]=[%d, %d]...',ress(1,1),ress(1,2));
img=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_mono_white_%dx%d.png',ress(1,1),ress(1,2))));
wimg(1:ress(1,2),1:ress(1,1),:)=img;
imwrite(wimg,sprintf('wallpaper_1_display_%dx%d.png',ress(1,1),ress(1,2)),'png');
fprintf('completed.\n');
% only disp 2 is used
elseif ress(1,1)==0 && ress(2,1)~=0 && ress(3,1)==0
fprintf('processing display 2 alone with resolution: [width, height]=[%d, %d]...',ress(2,1),ress(2,2));
img=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_mono_white_%dx%d.png',ress(2,1),ress(2,2))));
wimg(1:ress(2,2),1:ress(2,1),:)=img;
imwrite(wimg,sprintf('wallpaper_1_display_%dx%d.png',ress(2,1),ress(2,2)),'png');
fprintf('completed.\n');
% only disp 3 is used
elseif ress(1,1)==0 && ress(2,1)==0 && ress(3,1)~=0
fprintf('processing display 3 alone with resolution: [width, height]=[%d, %d]...',ress(3,1),ress(3,2));
img=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_mono_white_%dx%d.png',ress(3,1),ress(3,2))));
wimg(1:ress(3,2),1:ress(3,1),:)=img;
imwrite(wimg,sprintf('wallpaper_1_display_%dx%d.png',ress(3,1),ress(3,2)),'png');
fprintf('completed.\n');
% only disp 1 and 2 are used
elseif ress(1,1)~=0 && ress(2,1)~=0 && ress(3,1)==0
fprintf('processing display 1 & 2 with resolutions: [width, height]=[%d, %d] & [%d, %d]...',ress(1,1),ress(1,2),ress(2,1),ress(2,2));
img=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_mono_white_%dx%d.png',ress(2,1),ress(2,2))));
wimg(1:ress(2,2),ress(1,1)+1:ress(1,1)+ress(2,1),:)=img;
imwrite(wimg,sprintf('wallpaper_2_displays_%dx%d_%dx%d.png',ress(1,1),ress(1,2),ress(2,1),ress(2,2)),'png');
fprintf('completed.\n');
% only disp 1 and 3 are used
elseif ress(1,1)~=0 && ress(2,1)==0 && ress(3,1)~=0
fprintf('processing display 1 & 3 with resolutions: [width, height]=[%d, %d] & [%d, %d]...',ress(1,1),ress(1,2),ress(3,1),ress(3,2));
img=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_mono_white_%dx%d.png',ress(3,1),ress(3,2))));
wimg(1:ress(3,2),ress(1,1)+1:ress(1,1)+ress(3,1),:)=img;
imwrite(wimg,sprintf('wallpaper_2_displays_%dx%d_%dx%d.png',ress(1,1),ress(1,2),ress(3,1),ress(3,2)),'png');
fprintf('completed.\n');
% only disp 2 and 3 are used, bonocular displays without a separatre console display
elseif ress(1,1)==0 && ress(2,1)~=0 && ress(3,1)~=0
fprintf('processing display 2 & 3 with resolutions: [width, height]=[%d, %d] & [%d, %d]...',ress(2,1),ress(2,2),ress(3,1),ress(3,2));
img_L=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_left_magenda_%dx%d.png',ress(2,1),ress(2,2))));
img_R=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_right_cyan_%dx%d.png',ress(3,1),ress(3,2))));
wimg(1:ress(2,2),1:ress(2,1),:)=img_L;
wimg(1:ress(3,2),ress(2,1)+1:ress(2,1)+ress(3,1),:)=img_R;
imwrite(wimg,sprintf('wallpaper_2_displays_%dx%d_%dx%d.png',ress(2,1),ress(2,2),ress(3,1),ress(3,2)),'png');
fprintf('completed.\n');
% all 1-3 displays are used. the independent console + bonocular displays
elseif ress(1,1)~=0 && ress(2,1)~=0 && ress(3,1)~=0
fprintf('processing display all 1-3 with resolutions: [width, height]=[%d, %d], [%d, %d], [%d, %d]...',ress(1,1),ress(1,2),ress(2,1),ress(2,2),ress(3,1),ress(3,2));
img_L=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_left_magenda_%dx%d.png',ress(2,1),ress(2,2))));
img_R=imread(fullfile(fileparts(mfilename('fullpath')),'pngs',sprintf('image_right_cyan_%dx%d.png',ress(3,1),ress(3,2))));
wimg(1:ress(2,2),ress(1,1)+1:ress(1,1)+ress(2,1),:)=img_L;
wimg(1:ress(3,2),sum(ress([1,2],1))+1:sum(ress([1,2],1))+ress(3,1),:)=img_R;
imwrite(wimg,sprintf('wallpaper_3_displays_%dx%d_%dx%d_%dx%d.png',ress(1,1),ress(1,2),ress(2,1),ress(2,2),ress(3,1),ress(3,2)),'png');
fprintf('completed.\n');
else
error('at least one display should be set non-one value. check the parameters.');
end
return