-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpa_addTitel.m
More file actions
133 lines (127 loc) · 3.46 KB
/
jpa_addTitel.m
File metadata and controls
133 lines (127 loc) · 3.46 KB
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
function jpa_addTitel(plot)
% jpa_addTitel - adds a colorbar to a picture to a specified
% color-Scheme from MRIcroGL
%
% Syntax: jpa_addTitel(plot)
%
% Inputs:
% plot
% * plot.img - contains the path of the Image to load
% plot.bgcolor - Backgroundcolor of MRIcroGL-Images
% plot.titel.text - contains the Titel to be added
% plot.titel.position - 2x1, [left, bottom]
% plot.titel.FontSize - Font Size of text
%
% * = necessary for jpa_addTitel
%
%
% Outputs:
% .png - Picture saved in directory specified under plot.savePath
%
%
% Example:
% jpa_addTitel(plot)
% where:
% plot.img = 'C:\picturesToPlot\pic1.png'
% plot.savePath = 'C:\picturesToPlot\PicturesWithTitel';
% plot.bgcolor = [0 0 0]
% plot.titel.text = 'titel1'
% plot.titel.position = [0.1 0.1] -> top left site of Pic
% plot.titel.FontSize = 14
%
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: jpa_plotMriCro
% Author: Jan Albrecht
% Work address:
% email: jan-philipp.albrecht@charite.de, j.p.albrecht@fu-berlin.de
% Website:
% Sep 2015; Last revision: 04-Sep-2015
%------------- BEGIN CODE --------------
%% Standards if nothing specified
nobg = false;
if ~isfield(plot,'img') || isempty(plot.img)
error('No Image to load!');
end
[savePath,name] = fileparts(plot.img);
if ~isfield(plot,'savePath') || isempty(plot.savePath)|| strcmp('', plot.savePath)
disp(['no savePath given... will safe Picture in current directory: ' savePath]);
plot.savePath = savePath;
end
if ~isfield(plot,'bgcolor') || isempty(plot.bgcolor)
disp('no backgroundcolor given. Take Color of first Pixel...');
nobg = true;
end
if ~isfield(plot.titel,'text') || isempty(plot.titel.text)
plot.titel.text = 'titel1';
end
if ~isfield(plot.titel,'position') || isempty(plot.titel.position)
disp('no position given. Take Position top-left...');
plot.titel.position = [0.1 0.1];
end
if ~isfield(plot.titel,'FontSize') || isempty(plot.titel.FontSize)
disp('no FontSize given. Take Size 14...');
plot.titel.FontSize = 14;
end
%% Load Picture
try
pic = imread(plot.img);
[h w c] = size(pic);
% determine Backgroundcolor of pic
if nobg
plot.bgcolor(1) = pic(1,1,1);
plot.bgcolor(2) = pic(1,1,2);
plot.bgcolor(3) = pic(1,1,3);
end
catch ME
%Display
disp('Loading Image went wrong');
disp(strcat('Is this correct?: ',plot.img));
disp(ME.identifier)
end
figure(1)
g = image(pic);
%% Set Titel
set(g,'CDataMapping','scaled');
% remove Labels
set(gca,'XTickLabel',[])
set(gca,'YTickLabel',[])
% Modify axes size
set(gca,'Units','normalized','Position',[0 0 1 1]);
% Modify figure size
set(gcf,'Units','pixels','Position',[0 0 (w+1) (h+1)]);
% calculate Contrast to Backgroundcolor
cont = [0 0 0];
if plot.bgcolor(1) > 127/255
cont(1) = 0;
else
cont(1) = 255/255;
end
if plot.bgcolor(2) > 127/255
cont(2) = 0;
else
cont(2) = 255/255;
end
if plot.bgcolor(3) > 127/255
cont(3) = 0;
else
cont(3) = 255/255;
end
% calculate Position
y = w * plot.titel.position(1);
x = h * plot.titel.position(2);
t = text(y,x,plot.titel.text);
set(t,'Color',cont);
set(t,'FontSize', plot.titel.FontSize);
%% save Image with colorbar
f = getframe(gca);
im = frame2im(f);
if ~exist(plot.savePath, 'dir')
mkdir(plot.savePath);
end
imwrite(im,fullfile(plot.savePath ,strcat(name,'.png')));
end
%------------- END OF CODE --------------