Skip to content

Commit

Permalink
updated plotting to handle latest paper revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Close committed Jun 16, 2013
1 parent 978ae96 commit 4267fd8
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion bash/subtract_corpus
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ for subject_dir in $data_dir/corpus_callosum/*; do
num_runs=`ls $data_dir/corpus_callosum/$subject/$dw | wc | awk '{print $1}'`
mradd $data_dir/corpus_callosum/$subject/$dw/*/last.mif $data_dir/corpus_callosum/$subject/$dw/sum_last.mif
mrmath -force $data_dir/corpus_callosum/$subject/$dw/sum_last.mif $num_runs -divide $data_dir/corpus_callosum/$subject/$dw/avg_last.mif
mrmath -force $REFERENCE_DIR/$subject/images/fornix.$dw.no-iso.mif $data_dir/corpus_callosum/$subject/$dw/avg_last.mif -subtract $REFERENCE_DIR/$subject/images/fornix.$dw.no-corpus.mif
mrmath -force $REFERENCE_DIR/$subject/images/fornix.$dw.no-iso.mif $data_dir/corpus_callosum/$subject/$dw/avg_last.mif -subtract $REFERENCE_DIR/$subject/images/fornix.$dw.no-corpus_cst.mif
done
done
9 changes: 5 additions & 4 deletions matlab/add_lines_to_plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ function add_lines_to_plot(tcks, colours, bundle_indices)

for tck_i = 1:num_tcks

h = plot3(tcks{tck_i}(:,1), tcks{tck_i}(:,2), tcks{tck_i}(:,3));

set(h, 'Color', colours(bundle_indices(tck_i)+1,:));

if ~isempty(tcks{tck_i})
h = plot3(tcks{tck_i}(:,1), tcks{tck_i}(:,2), tcks{tck_i}(:,3));

set(h, 'Color', colours(bundle_indices(tck_i)+1,:));
end
end

hold off;
Expand Down
16 changes: 9 additions & 7 deletions matlab/fourier2tck.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@


if (degree < 1)
error('Fourier coefficients have degree of less than 1');
end
disp('WARNING! Fourier coefficients have degree of less than 1');
tck = [];
else
psi = ones(num_points,1);

for (d = [1:(degree-1)])

psi = ones(num_points,1);
psi = [psi, sqrt(2) * cos(pi * k * d)];

for (d = [1:(degree-1)])

psi = [psi, sqrt(2) * cos(pi * k * d)];
end

tck = psi * fourier;
end

tck = psi * fourier;
19 changes: 7 additions & 12 deletions matlab/get_observed_properties.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function [dims, true_location, voxel_lengths, offset, obs_image_location] = get_observed_properties(properties, obs_image_location)

if ~exist('obs_image_location', 'var')
obs_image_location = [];
obs_image_location = [];
end

true_location = [];
Expand All @@ -16,6 +16,8 @@
offset = [0 0 0];
return;
end
else
disp('here')
end

f = fopen (obs_image_location, 'r');
Expand All @@ -27,6 +29,8 @@
if (f<1)
disp (['Warning!! could not open observed image file ''' obs_image_location ''' to determine image dimensions']);
dims = [3,3,3];
voxel_lengths = [0 0 0 0];
offset = [0 0 0];
return
end
end
Expand All @@ -35,6 +39,8 @@
fclose(f);
disp (['Warning!! observed image file ''' obs_image_location ''' is not in MRtrix format, could not determine image dimensions.']);
dims = [3 3 3];
voxel_lengths = [0 0 0 0];
offset = [0 0 0];
return
end

Expand Down Expand Up @@ -67,18 +73,7 @@
offset = cell2mat(offset);

fclose(f);

% if isempty(dims)
% disp('Warning!! Observed image location did not specifiy image dimensions.');
% dims = [3 3 3];
% end
%
% if isempty(true_location)
% disp('Warning!! Observed image location did not specifiy inital location.');
% end



end


Expand Down
36 changes: 21 additions & 15 deletions matlab/plot_tract_sets.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main_fig = plot_tracts_sets(varargin)
function [main_fig, num_voxels, voxel_lengths, voxel_offsets] = plot_tracts_sets(varargin)
%
% PURPOSE: Plots strands from strand files, and optionally displays reference sphere and voxels
%
Expand Down Expand Up @@ -94,9 +94,10 @@
'last', 0, 'bool', 'Overrides ''-include'' to only print the last tract set.';...
'tract_include ', [], 'matrix_:x:', 'The indices of the tracts to include in the plot';...
'colours_of_bundles', colours_of_bundles, 'matrix_:x3', 'Colours of the plotted strands';...
'voxel_size ', 0.15, 'float', 'Size of reference voxel';...
'voxel_trans ', 0.25, 'float', 'The alpha value of the voxel lines';...
'num_voxels ', -1, 'int', 'Number of reference voxels';...
'num_voxels ', [], 'matrix_1x3', 'Number of reference voxels';...
'voxel_lengths', [], 'matrix_1x3', 'Size of reference voxel';...
'voxel_offsets ', [], 'matrix_1x3', 'Offset of reference voxels';...
'voxel_transparency', 0.25, 'float', 'The alpha value of the voxel lines';...
'cube_size ', 0, 'float', 'Size of reference voxel';...
'strand_radius ', 0.02, 'float', 'Radii of the plotted strands. (NB: can only be used with ''-style'' option ''strands'').';...
'style ', 'tracts', 'string', 'Change plot to ''line style''.(NB: Only relevant with ''-num_width_sections'' option > 0).';...
Expand All @@ -119,7 +120,7 @@
'hold_on', 0, 'bool', 'Adds the plot to the previous figure';...
'highlight_axes', 0, 'bool', 'Highlights the axes when printing in ''strand'' or ''line'' style';...
'invisible', 0, 'bool', 'Makes the figure invisible (for automatically saving afterwards).';...
'obs_image', [], 'string', 'Overlays a slice along the x observed image.';...
'obs_image_loc', [], 'string', 'Overlays a slice along the x observed image.';...
'slice_x', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.';...
'slice_y', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.';...
'slice_z', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.'};
Expand Down Expand Up @@ -165,12 +166,21 @@

num_sets = size(tract_sets,1);

[num_voxels, true_location, voxel_length, voxel_offset, obs_image] = get_observed_properties(properties, obs_image);
if isempty(num_voxels) %#ok<NODEF>
[num_voxels, true_location, voxel_lengths, voxel_offsets, obs_image] = get_observed_properties(properties, obs_image_loc);
if ~isempty(num_voxels)
num_voxels = num_voxels(1:3);
voxel_lengths = voxel_lengths(1:3);
end
elseif isempty(voxel_offsets) %#ok<NODEF>
voxel_offsets = - num_voxels .* voxel_lengths ./2;
end


if (ndims(num_voxels) == 1 || true_tracts_plot)
if (num_voxels < 0 || true_tracts_plot)
num_voxels = num_voxels(1:3);
voxel_length = voxel_length(1:3);
voxel_lengths = voxel_lengths(1:3);
end
end

Expand Down Expand Up @@ -339,14 +349,10 @@

add_mri_slice_to_plot(obs_image, slice_x, slice_y, slice_z)

elseif voxel_size ~= 0 || isempty(voxel_length)

if isempty(voxel_length)
voxel_length = [voxel_size, voxel_size, voxel_size];
end

add_vox_lines_to_plot(voxel_length,num_voxels,~no_voxline_highlight,...
voxel_offset, voxel_trans);
elseif ~isempty(num_voxels)

add_vox_lines_to_plot(voxel_lengths,num_voxels,~no_voxline_highlight,...
voxel_offsets, voxel_transparency);

end

Expand Down
100 changes: 48 additions & 52 deletions matlab/plot_tracts.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% Colours of the plotted strands
% matrix_:x3
%
% -voxel_size
% -voxel_lengths
% Size of reference voxel
% float
% 0.15
Expand Down Expand Up @@ -120,35 +120,36 @@
arguments = {'tracts_filename', 'The filename of the tracts (''.tct'' format).'};

options = {...
'include ', [], 'matrix_:x:', 'The indices of the strands to include in the plot';...
'colours_of_bundles', colours_of_bundles, 'matrix_:x3', 'Colours of the plotted strands';...
'voxel_size ', 0.15, 'float', 'Size of reference voxel';...
'voxel_trans ', 0.25, 'float', 'The alpha value of the voxel lines';...
'num_voxels ', -1, 'int', 'Number of reference voxels';...
'cube_size ', 0, 'float', 'Size of reference voxel';...
'num_length_sections ', 100, 'int', 'Number of segments to plot for each tract.';...
'strand_radius ', 0.02, 'float', 'Radii of the plotted strands. (NB: can only be used with ''-style'' option ''strands'').';...
'num_width_sections ', 2, 'int', 'Number of strands to plot along each axis. If zero the default 3D surface option will be used instead.';...
'strands_per_acs', -1, 'float', 'Instead of a fixed number of width sections the number of plotted strands is determined by the ACS of the tract';...
'style ', 'tractlets', 'string', 'Change plot to ''line style''.(NB: Only relevant with ''-num_width_sections'' option > 0).';...
'tube_corners ', 12, 'int', 'Change plot to ''line style''.(NB: Only relevant with ''-num_width_sections'' option = 0).';...
'sphere_radius ', 0, 'float', 'Size of reference sphere';...
'no_axes', 0, 'bool', 'Removes axes from plot';...
'clean', 0, 'bool', 'Removes everything else from plot';...
'colour_key', 0, 'bool', 'Displays colour key';...
'oblong', 0, 'bool', 'Prints an oblong tractlet rather than cylindrical';...
'happy_colours', 0, 'bool', 'Uses ''happy colours''';...
'inv_happy_colours', 0, 'bool', 'Uses the inverse of ''happy colours''';...
'ignore_bundles', 0, 'bool', 'Ignores bundle indices when plotting colours.';...
'no_voxline_highlight', 0, 'bool', 'Doesn''t highlight corner axes of voxel lines.';...
'transparency' ,1, 'float', 'Fix the transparency of the tracts to a set value. If 0 the intensities of the of the tracts are used instead.';...
'highlight_axes', 0, 'bool', 'Highlights the axes when printing in ''strand'' or ''line'' style';...
'invisible', 0, 'bool', 'Makes the figure invisible (for automatically saving afterwards).';...
'hold_on' , 0, 'bool', 'plot on previous figure'...
'obs_image', [], 'string', 'Overlays a slice along the x observed image.';...
'slice_x', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.';...
'slice_y', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.';...
'slice_z', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.'};
'include ', [], 'matrix_:x:', 'The indices of the strands to include in the plot';...
'colours_of_bundles', colours_of_bundles, 'matrix_:x3', 'Colours of the plotted strands';...
'num_voxels ', [], 'matrix_1x3', 'Number of reference voxels';...
'voxel_lengths', [], 'matrix_1x3', 'Size of reference voxel';...
'voxel_offsets ', [], 'matrix_1x3', 'Offset of reference voxels';...
'voxel_transparency', 0.25, 'float', 'The alpha value of the voxel lines';...
'cube_size ', 0, 'float', 'Size of reference voxel';...
'num_length_sections ', 100, 'int', 'Number of segments to plot for each tract.';...
'strand_radius ', 0.02, 'float', 'Radii of the plotted strands. (NB: can only be used with ''-style'' option ''strands'').';...
'num_width_sections ', 2, 'int', 'Number of strands to plot along each axis. If zero the default 3D surface option will be used instead.';...
'strands_per_acs', -1, 'float', 'Instead of a fixed number of width sections the number of plotted strands is determined by the ACS of the tract';...
'style ', 'tractlets','string', 'Change plot to ''line style''.(NB: Only relevant with ''-num_width_sections'' option > 0).';...
'tube_corners ', 12, 'int', 'Change plot to ''line style''.(NB: Only relevant with ''-num_width_sections'' option = 0).';...
'sphere_radius ', 0, 'float', 'Size of reference sphere';...
'no_axes', 0, 'bool', 'Removes axes from plot';...
'clean', 0, 'bool', 'Removes everything else from plot';...
'colour_key', 0, 'bool', 'Displays colour key';...
'oblong', 0, 'bool', 'Prints an oblong tractlet rather than cylindrical';...
'happy_colours', 0, 'bool', 'Uses ''happy colours''';...
'inv_happy_colours', 0, 'bool', 'Uses the inverse of ''happy colours''';...
'ignore_bundles', 0, 'bool', 'Ignores bundle indices when plotting colours.';...
'no_voxline_highlight', 0, 'bool', 'Doesn''t highlight corner axes of voxel lines.';...
'transparency' , 1, 'float', 'Fix the transparency of the tracts to a set value. If 0 the intensities of the of the tracts are used instead.';...
'highlight_axes', 0, 'bool', 'Highlights the axes when printing in ''strand'' or ''line'' style';...
'invisible', 0, 'bool', 'Makes the figure invisible (for automatically saving afterwards).';...
'hold_on' , 0, 'bool', 'plot on previous figure';...
'obs_image', [], 'string', 'Overlays a slice along the x observed image.';...
'slice_x', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.';...
'slice_y', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.';...
'slice_z', [], 'matrix_:x:', 'Overlays slices of observed image along the given indices.'};


parse_arguments
Expand All @@ -157,7 +158,7 @@
end

if clean
voxel_size = 0;
voxel_lengths = 0;
sphere_radius = 0;
no_axes = 1;
end
Expand Down Expand Up @@ -190,12 +191,14 @@

num_loaded_tracts = size(tracts,1);

[num_voxels, ~, voxel_length, voxel_offset, obs_image] = get_observed_properties(props, obs_image);

if (num_voxels < 0)

num_voxels = num_voxels(1:3);
voxel_length = voxel_length(1:3);
if isempty(num_voxels) %#ok<NODEF>
[num_voxels, ~, voxel_lengths, voxel_offsets, obs_image] = get_observed_properties(props, obs_image);
if ~isempty(num_voxels)
num_voxels = num_voxels(1:3);
voxel_lengths = voxel_lengths(1:3);
end
elseif isempty(voxel_offsets) %#ok<NODEF>
voxel_offsets = - num_voxels .* voxel_lengths ./2;
end

acs = get_properties(prop_keys, prop_values, 'alpha', (0:(num_loaded_tracts-1))', num_loaded_tracts).^2;
Expand Down Expand Up @@ -240,7 +243,7 @@

% If '-num_width_sections' parameter is not set plot the boundary of the tract
% instead.
if strfind(style, 'tractlets') == 1
if strfind(style, 'tracts') ~= 0

if oblong
error('''-oblong'' option cannot be used with ''tracts'' style');
Expand All @@ -253,7 +256,8 @@

add_tracts_to_plot(tracts, colours_of_bundles, ones(num_tracts,1), ones(num_tracts,1), tube_corners, num_length_sections, transparency, bundle_indices);

elseif strfind(style, 'tubes') == 1
end
if strfind(style, 'tubes') ~= 0

[strands, bundle_indices] = tracts2strands(tracts, ones(num_tracts,1), num_width_sections, highlight_axes, oblong, bundle_indices, strands_per_acs, acs);
tcks = strands2tcks(strands);
Expand All @@ -264,17 +268,13 @@

%[tcks, colours_of_bundles] = display_strands(tcks, colours_of_bundles, include, 'bundle', line_style);

elseif strfind('lines', style) == 1
end
if strfind(style, 'lines') ~= 0

[strands, bundle_indices] = tracts2strands(tracts, ones(num_tracts,1), num_width_sections, highlight_axes, oblong, bundle_indices, strands_per_acs, acs);
tcks = strands2tcks(strands);

add_lines_to_plot(tcks, colours_of_bundles, bundle_indices);

else

error(['Urecogised style option ''' style '''.']);

end

add_sphere_to_plot(sphere_radius);
Expand All @@ -284,14 +284,10 @@

add_mri_slice_to_plot(obs_image, slice_x, slice_y, slice_z)

elseif voxel_size ~= 0 || isempty(voxel_length)

if isempty(voxel_length)
voxel_length = [voxel_size, voxel_size, voxel_size];
end
elseif ~isempty(num_voxels)

add_vox_lines_to_plot(voxel_length,num_voxels,~no_voxline_highlight,...
voxel_offset, voxel_trans);
add_vox_lines_to_plot(voxel_lengths,num_voxels,~no_voxline_highlight,...
voxel_offsets, voxel_transparency);

end

Expand Down

0 comments on commit 4267fd8

Please sign in to comment.