Skip to content

Commit ba83375

Browse files
committed
Inverse masking, outlining of colorbar bins in map, colorbar aligned tick labels
- Keep everything outside of a mask image (inverse masking; added to contextual menu for mask button) - Create outlines for each bin in your colormap (as one image; added to outline dropdown menu for overlays) - Tick labels were not aligned to the edges of the colorbar or to colorbar bins (and were not centered) - Added warning when tick labels purposefully do not align to colorbar bins - When binarizing underlays, number of bins in the colormap is no longer manipulable to prevent some bugs. Use the color buttons in the underlay data panel to assign different colors than those used by the colormap
1 parent e7be9da commit ba83375

File tree

5 files changed

+64
-19
lines changed

5 files changed

+64
-19
lines changed

GUIs/oSelect.mlapp

195 Bytes
Binary file not shown.

brainSurfer.mlapp

1.52 KB
Binary file not shown.

scripts/patch/colormapper.m

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [cMap,cData,cbData,ticks,tickLabels] = colormapper(data,varargin)
1+
function [cMap,cData,cbData,ticks,tickLabels,m] = colormapper(data,varargin)
22
% This function generates a colormap using various specifications.
33
%
44
% Mandatory arguments------------------------------------------------------
@@ -50,6 +50,7 @@
5050
% [cMap,cData,cbData,ticks,tickLabels] = colormapGenerator(data,'colormap','delta','colorSpacing','even','colorBins',1000,'colorSpecial','randomizeClusterColors','invertColors','false')
5151

5252
% Defaults
53+
m = [];
5354
options = struct('colormap', 'jet','colorSpacing','even','colorBins',1000,'colorSpecial','none','invertColors','false','limits',[min(data) max(data)],'sulci',[],'gyri',[],'thresh',[]);
5455
optionNames = fieldnames(options);
5556

@@ -80,6 +81,8 @@
8081
warning('Colormap is adjusted...if centering on zero must have even number of color bins')
8182
options.colorBins=options.colorBins-1;
8283
end
84+
case 'even'
85+
%options.colorBins = options.colorBins+1;
8386
end
8487

8588
% create colormap if a string is passed in...otherwise interpolate colors
@@ -293,15 +296,23 @@
293296
% this is the default option. All values between limits will get a
294297
% color from your colormap.
295298
case 'even'
296-
cbData = linspace(min(options.limits),max(options.limits),options.colorBins);
299+
cbData = linspace(min(options.limits),max(options.limits),options.colorBins+1);
297300
% this will split your colormap into negative and positive values.
298301
% Negative stuff gets half the colormap. positive stuff gets the other
299302
% half.
300-
ticks = linspace(min(options.limits),max(options.limits),11);
301-
tickLabels = ticks;
303+
if length(cbData) <= 21
304+
ticks = cbData;
305+
else
306+
ticks = linspace(min(options.limits),max(options.limits),21);
307+
warning('Colorbar labels are in the correct position but may not match the location of each bin on the colormap because you have too many bins in your colormap and we cannot display ticks for all of them')
308+
end
302309

310+
tickLabels = ticks;
303311
tf = cbData >= data;
304-
[~,m] = max(tf,[],2);
312+
[~,m] = min(fliplr(tf), [], 2);
313+
m = size(tf, 2) - m + 1;
314+
id = find(m > options.colorBins);
315+
m(id) = options.colorBins; % we need to clip everything above the limit to the last colorbin
305316
cData = cMap(m,:);
306317

307318
case 'center on zero'

scripts/patch/patchOverlay.m

+33-11
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
end
238238

239239
% Get clusters if they are needed
240-
if options.clusterThresh ~= 0 | options.grow ~= 0 | strcmpi(options.outline,'map') | strcmpi(options.binarize,'clusters') == 1 | ~isempty(options.priorClusters)
240+
if options.clusterThresh ~= 0 | options.grow ~= 0 | strcmpi(options.outline,'map') | strcmpi(options.outline,'bins') | strcmpi(options.binarize,'clusters') == 1 | ~isempty(options.priorClusters)
241241
if ~isempty(options.UI)
242242
d.Message = ['Finding blobs...this may take some time if you have large blobs in your map'];
243243
d.Value = 0.1;
@@ -302,20 +302,35 @@
302302
options.clusters = dataClust;
303303
end
304304

305+
% Bin-based outlines are a little different too...we will turn bins into
306+
% clusters...
307+
if strcmpi(options.outline,'bins')
308+
% other outline functions have to occur before colormapping so this is
309+
% temporary...
310+
warning('This option is still under development!!! It may break lots of things.')
311+
[colormapMapTmp,cDataTmp,colormapdataMapTmp,ticksTicksTmp,tickslabelsTmp,m] = colormapper(dataT{:},'colormap',options.colormap{1},'colorSpacing',options.colorSpacing{1},'colorBins',options.colorBins{1},'colorSpecial',options.colorSpecial{1},'invertColors',options.invertColors{1},'limits',[min(options.limits{1}) max(options.limits{1})],'thresh',options.thresh{1});
312+
un = unique(m);
313+
clear dataClust
314+
for i = 1:length(un)
315+
dataClust{i} = find(m == un(i));
316+
end
317+
end
318+
305319
% Turn clusters into boundaries if necessary
306320
if ~strcmpi(options.outline,'none') | options.grow ~= 0
307321
if ~isempty(options.UI)
308322
d.Message = ['Fetching boundary vertices...'];
309323
d.Value = 0.2;
310324
end
311-
dataClust_all = dataClust;
312-
if strcmpi(options.outline,'roi')
313-
dataClust2 = getClusterBoundary(dataClust, underlays.(hemi).Faces);
314-
dataClust = cellfun(@(x,y) setdiff(x,intersect(vertcat(dataClust2{:}),x)),dataClust,dataClust2, 'UniformOutput', false);
315-
end
316-
317-
dataClust = getClusterBoundary(dataClust, underlays.(hemi).Faces);
318-
hz = horzcat(dataT{:});
325+
326+
dataClust_all = dataClust;
327+
if strcmpi(options.outline,'roi')
328+
dataClust2 = getClusterBoundary(dataClust, underlays.(hemi).Faces);
329+
dataClust = cellfun(@(x,y) setdiff(x,intersect(vertcat(dataClust2{:}),x)),dataClust,dataClust2, 'UniformOutput', false);
330+
end
331+
332+
dataClust = getClusterBoundary(dataClust, underlays.(hemi).Faces);
333+
hz = horzcat(dataT{:});
319334

320335
for clusteri = 1:length(dataClust)
321336
% if you are doing an outline we need to get mean value for
@@ -474,7 +489,9 @@
474489
for di = 1:length(dataTS)
475490
%if length(dataTS) == 1 | (length(dataTS) > 1 & (isempty(options.multiCmap) | isempty(options.multiCmapTicks) | isempty(options.multiCbData)))
476491
if length(dataTS) == 1 | length(dataTS) > 1 | isempty(options.multiCmapTicks) | isempty(options.multiCbData)
477-
[colormapMapTmp,cDataTmp,colormapdataMapTmp,ticksTicksTmp,tickslabelsTmp] = colormapper(dataTS{di},'colormap',options.colormap{di},'colorSpacing',options.colorSpacing{di},'colorBins',options.colorBins{di},'colorSpecial',options.colorSpecial{di},'invertColors',options.invertColors{di},'limits',[min(options.limits{di}) max(options.limits{di})],'thresh',options.thresh{di});
492+
if ~strcmpi(options.outline,'bins')
493+
[colormapMapTmp,cDataTmp,colormapdataMapTmp,ticksTicksTmp,tickslabelsTmp] = colormapper(dataTS{di},'colormap',options.colormap{di},'colorSpacing',options.colorSpacing{di},'colorBins',options.colorBins{di},'colorSpecial',options.colorSpecial{di},'invertColors',options.invertColors{di},'limits',[min(options.limits{di}) max(options.limits{di})],'thresh',options.thresh{di});
494+
end
478495
colormap{di}.map = colormapMapTmp;
479496
cData{di} = cDataTmp;
480497
colormap{di}.dataMap = colormapdataMapTmp;
@@ -625,11 +642,16 @@
625642
% find alpha mapping for each "color" here. transp.map will be this.
626643
% transp.vals can be alph from below.
627644
try
628-
transp.map = ones(size(colormap{1}.dataMap))*options.opacity;
645+
if strcmpi(options.colorSpacing,'even')
646+
transp.map = ones(1,length(colormap{1}.dataMap)-1)*options.opacity;
647+
else
648+
transp.map = ones(size(colormap{1}.dataMap))*options.opacity;
649+
end
629650
catch
630651
transp.map = ones(size(options.multiCbData,1),1)*options.opacity;
631652
end
632653

654+
633655
% if strcmpi(options.inclZero,'off') & isempty(s)
634656
% id = find(all(horzcat(dataTS{:}) == 0,2)==1);
635657
% transp.vals(id) = 0;

scripts/patch/patchUnderlaySG.m

+15-3
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,18 @@
226226
id2 = find(lo < options.binarize);
227227
lo(id1) = 1;
228228
lo(id2) = 0.01;
229+
options.colorBins = 2;
230+
[~,mi] = min(options.limits);
231+
options.limits(mi) = 0;
229232
end
230233
if ~isempty(options.rh)
231234
id1 = find(ro >= options.binarize);
232235
id2 = find(ro < options.binarize);
233236
ro(id1) = 1;
234237
ro(id2) = 0.01;
238+
options.colorBins = 2;
239+
[~,mi] = min(options.limits);
240+
options.limits(mi) = 0;
235241
end
236242
end
237243

@@ -270,13 +276,19 @@
270276
if isempty(options.limits) || ~isempty(options.binarize)
271277
if ~isempty(options.lh) && ~isempty(options.rh)
272278
tmp = [los; ros];
273-
options.limits(1,1) = min(tmp);
279+
if isempty(options.binarize)
280+
options.limits(1,1) = min(tmp);
281+
end
274282
options.limits(1,2) = max(tmp);
275283
elseif ~isempty(options.lh) && isempty(options.rh)
276-
options.limits(1,1) = min(options.lh);
284+
if isempty(options.binarize)
285+
options.limits(1,1) = min(options.lh);
286+
end
277287
options.limits(1,2) = max(options.lh);
278288
elseif isempty(options.lh) && ~isempty(options.rh)
279-
options.limits(1,1) = min(options.rh);
289+
if isempty(options.binarize)
290+
options.limits(1,1) = min(options.rh);
291+
end
280292
options.limits(1,2) = max(options.rh);
281293
end
282294
end

0 commit comments

Comments
 (0)