-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp_imsc.m
61 lines (58 loc) · 2.12 KB
/
sp_imsc.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
function h = sp_imsc(matrix, heatmap_colormaps, show_colorbar, limits)
% function sp_imsc(matrix, heatmap_colormaps, show_colorbar, limits)
%
% A wrapper to imsc, with some default options set.
%
% INPUTS:
% matrix : [matrix] of data
% [heatmap_colormaps]: [cell array] of colormap strings OR a string. Default: 'jet'
% [show_colorbar] : [boolean] Default: true
% [limits] : [min max] where values in image less than min will be set to
% min and values greater than max will be set to max.
%
% OUTPUTS:
% h : [handle]
%
% Sagi Perel, 01/2013
if(nargin < 1 || nargin > 4)
error('sp_imsc: wrong number of input arguments provided');
end
if(~sp_ismatrix(matrix))
error('sp_imsc: matrix should be a 2D matrix');
end
if(~exist('heatmap_colormaps','var') || isempty(heatmap_colormaps))
heatmap_colormaps = {'jet'};
elseif(ischar(heatmap_colormaps))
heatmap_colormaps = {heatmap_colormaps};
elseif(~iscell(heatmap_colormaps))
error('sp_imsc: heatmap_colormaps must be a cell array');
elseif(~all(cellfun(@ischar, heatmap_colormaps)))
error('sp_imsc: heatmap_colormaps must be a cell array of strings');
end
if(~exist('show_colorbar','var') || isempty(show_colorbar))
show_colorbar = true;
end
if(~exist('limits','var') || isempty(limits))
limits = [];
elseif(~sp_isvector(limits))
error('sp_imsc: limits must be a vector');
elseif(length(limits)~=2)
error('sp_imsc: limits must be a vector [min max]');
end
% make colormap limited to 5th-9th prctiles
prctiles = prctile(matrix(:),[5 95]);
matrix(matrix < prctiles(1)) = prctiles(1);
matrix(matrix > prctiles(2)) = prctiles(2);
for i=1:length(heatmap_colormaps)
if(i>1)
figure;
end
if(isempty(limits))
h = imsc(matrix, heatmap_colormaps{i}, 'w');
else
h = imsc(matrix, heatmap_colormaps{i}, limits, 'w');
end
if(show_colorbar)
colorbar;
end
end