Skip to content

Commit

Permalink
Bug fix for lowerbound truncation of colormap and support for scaled …
Browse files Browse the repository at this point in the history
…transparency
  • Loading branch information
bogpetre committed Sep 13, 2023
1 parent 157bb94 commit 7136038
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
34 changes: 32 additions & 2 deletions CanlabCore/@image_vector/render_on_surface.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
% 'colormap' argument as well, otherwise this does nothing and a
% warning is thrown.
%
% **'scaledtransparency':**
% Transparency is a function of voxel value, lower values are more transparent. This will look very
% strange without an underlay. To create an underlay render a two duplicate surfaces and invoke
% render_on_surface only on the second duplicate.
%
% **'transcontrast':**
% If scaledtransparency is used transparency alpha values are a linear function of the data. This
% option makes them a sigmoidal function of the data with higher values disproportionately opaque and
% lower values disproportionately transparent. This argument is followed by a scalar value which
% specifies how steep the sigmoidal part of the contrast curve should be. It works like a contrast
% curve in photoshop, but only affects alpha transparency, not colormapping, and therefore does not
% alter the data being shown.
%
% :Outputs:
%
% **renders colors on surfaces:**
Expand Down Expand Up @@ -152,6 +165,8 @@
dolegend = true;
doindexmap = false;
splitcolors = {};
doscaledtrans = 0;
enhance_contrast = @(x1)(x1);

allowable_keyword_value_pairs = {'clim' 'color' 'colormap' 'colormapname' 'axis_handle' 'pos_colormap' 'neg_colormap'};

Expand Down Expand Up @@ -202,8 +217,13 @@

doindexmap = true;



case 'scaledtransparency'
doscaledtrans = 1;

case 'transcontrast'
k = varargin{i+1};
enhance_contrast = @(x1)(2*((1./(1+exp(-k.*x1)))-0.5));

case allowable_keyword_value_pairs

eval([varargin{i} ' = varargin{i+1}; varargin{i+1} = [];']);
Expand Down Expand Up @@ -335,6 +355,9 @@
% Needed to map to vertices later
[~, ~, mesh_struct] = reconstruct_image(obj); % get volume data for slices

% fixes colormap out of range bug
mesh_struct.voldata(mesh_struct.voldata < min(clim)) = min(clim);

% Deal with edge interpolation effects
% problem is that vertices near empty (zero) voxels get interpolated down to zero
% solution: map all non-zero voxels to lowest limit value
Expand Down Expand Up @@ -454,6 +477,13 @@
set(surface_handles(i), 'CDataMapping', 'direct')
set(surface_handles(i), 'EdgeColor', 'none');

if doscaledtrans
z = c/max(abs(c));
z = enhance_contrast(z);
set(surface_handles(i), 'FaceVertexAlphaData',abs(z));
set(surface_handles(i), 'FaceAlpha', 'interp');
end

end

% Colorbars - legend
Expand Down
8 changes: 0 additions & 8 deletions CanlabCore/fmridisplay_helper_functions/render_blobs.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@
% curve in photoshop, but only affects alpha transparency, not colormapping, and therefore does not
% alter the data being shown.
%
% **'transcontrast':**
% If scaledtransparency is used transparency alpha values are a linear function of the data. This
% option makes them a sigmoidal function of the data with higher values disproportionately opaque and
% lower values disproportionately transparent. This argument is followed by a scalar value which
% specifies how steep the sigmoidal part of the contrast curve should be. It works like a contrast
% curve in photoshop, but only affects alpha transparency, not colormapping, and therefore does not
% alter the data being shown.
%
%
% **OTHER OPTIONS:**
%
Expand Down

0 comments on commit 7136038

Please sign in to comment.