Skip to content

Commit

Permalink
* Use progress bar instead of listing files in Normalise:Write (impro…
Browse files Browse the repository at this point in the history
…vements still required for 4D files)

* Allow syntax: spm_check_registration img1.nii img2.nii img3.nii
* Highlight current volume when using spm_orthviews' browser plugin

SVN r5700
  • Loading branch information
gllmflndn committed Oct 17, 2013
1 parent 977f72b commit 8cdf53b
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 174 deletions.
256 changes: 124 additions & 132 deletions config/spm_cfg_norm.m

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions config/spm_run_norm.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
% Output:
% out - computation results, usually a struct variable.
%__________________________________________________________________________
% Copyright (C) 2005-2011 Wellcome Trust Centre for Neuroimaging
% Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging

% $Id: spm_run_norm.m 5700 2013-10-17 14:59:50Z guillaume $

% $Id: spm_run_norm.m 5261 2013-02-19 16:37:37Z john $

for i=1:numel(job.subj)

Expand Down Expand Up @@ -85,25 +86,24 @@ function write_norm(job)
defs.out{1}.pull.mask = 1;
defs.out{1}.pull.fwhm = [0 0 0];

for i=1:numel(job.subj),
for i=1:numel(job.subj)
defs.out{1}.pull.fnames = job.subj(i).resample;
if ~isfield(job.subj(i),'def')
defs.comp{1}.def = {spm_file(char(job.subj(i).vol), 'prefix','y_', 'ext','.nii')};
defs.comp{1}.def = {spm_file(char(job.subj(i).vol), 'prefix','y_', 'ext','.nii')};
else
defs.comp{1}.def = job.subj(i).def;
defs.comp{1}.def = job.subj(i).def;
end

Nii = nifti(defs.comp{1}.def);
vx = sqrt(sum(Nii.mat(1:3,1:3).^2));
o = Nii.mat\[0 0 0 1]';
o = o(1:3)';
dm = size(Nii.dat);
bb = [-vx.*(o-1) ; vx.*(dm(1:3)-o)];
vx = sqrt(sum(Nii.mat(1:3,1:3).^2));
o = Nii.mat\[0 0 0 1]';
o = o(1:3)';
dm = size(Nii.dat);
bb = [-vx.*(o-1) ; vx.*(dm(1:3)-o)];

defs.comp{2}.idbbvox.vox = job.woptions.vox;
defs.comp{2}.idbbvox.bb = job.woptions.bb;
defs.comp{2}.idbbvox.vox(~isfinite(defs.comp{2}.idbbvox.vox)) = vx(~isfinite(defs.comp{2}.idbbvox.vox));
defs.comp{2}.idbbvox.bb(~isfinite(defs.comp{2}.idbbvox.bb)) = bb(~isfinite(defs.comp{2}.idbbvox.bb));
spm_deformations(defs);
end

63 changes: 46 additions & 17 deletions spm_check_registration.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function spm_check_registration(images, captions, varargin)
function spm_check_registration(varargin)
% A visual check of image registration quality
% FORMAT spm_check_registration
% FORMAT spm_check_registration(images, captions)
% FORMAT spm_check_registration(images)
% Orthogonal views of one or more images are displayed. Clicking in
% any image moves the centre of the orthogonal views. Images are
% shown in orientations relative to that of the first selected image.
Expand All @@ -12,28 +12,55 @@ function spm_check_registration(images, captions, varargin)
% Copyright (C) 1997-2013 Wellcome Trust Centre for Neuroimaging

% John Ashburner
% $Id: spm_check_registration.m 5360 2013-03-27 13:59:27Z guillaume $
% $Id: spm_check_registration.m 5700 2013-10-17 14:59:50Z guillaume $

SVNid = '$Rev: 5700 $';

SVNid = '$Rev: 5360 $';

if ~nargin
%-Get input
%--------------------------------------------------------------------------
if nargin
if nargin > 1 && iscellstr(varargin{2})
images = varargin{1};
elseif isstruct(varargin{1})
images = [varargin{:}];
else
images = char(varargin);
end
else
[images, sts] = spm_select([1 24],'image','Select images');
if ~sts, return; end
end

if ischar(images), images = spm_vol(images); end
images = images(1:min(numel(images),24));

%-Print
%--------------------------------------------------------------------------
spm('FnBanner',mfilename,SVNid); %-#
exactfname = @(f) [f.fname ',' num2str(f.n(1))];
if desktop('-inuse')
dispf = @(f) sprintf('<a href="matlab:spm_image(''display'',''%s'');">%s</a>',f,f);
else dispf = @(f) f;
href = '<a href="matlab:%s;">%s</a>';
cmd = 'spm_image(''display'',''%s'')';
dispone = @(f) sprintf(href,sprintf(cmd,f),f);
cmd = 'spm_check_registration(%s)';
str = [];
for i=1:numel(images)
str = [str sprintf('''%s'',',exactfname(images(i)))];
end
dispall = @(f) sprintf([' (' href ') '],sprintf(cmd,str(1:end-1)),'all');
else
dispone = @(f) f;
dispall = @(f) ' ';
end
for i=1:numel(images)
if i==1, fprintf('Display '); else fprintf(' '); end %-#
fprintf('%s\n',dispf([images(i).fname ',' num2str(images(i).n(1))]));%-#
if i==1, fprintf('Display '); %-#
elseif i==2, fprintf('%s',dispall(images));
else fprintf(' '); end
fprintf('%s\n',dispone(exactfname(images(i)))); %-#
end

%-Display
%--------------------------------------------------------------------------
spm_figure('GetWin','Graphics');
spm_figure('Clear','Graphics');
spm_orthviews('Reset');
Expand All @@ -51,11 +78,13 @@ function spm_check_registration(images, captions, varargin)
[j+ds/2 i+ds/2 w-ds h-ds]);
if ij==1, spm_orthviews('Space'); end
spm_orthviews('AddContext',handle);
if nargin > 1 && ~isempty(captions)
captions = cellstr(captions);
mn = numel(captions);
if ij <= mn
spm_orthviews('Caption', ij, captions{ij}, varargin{:});
end
end
end

%-Backward compatibility with spm_check_registration(images,captions)
%--------------------------------------------------------------------------
if nargin > 1 && iscellstr(varargin{2})
spm_orthviews('Caption',varargin{2}, varargin{3:end});
%for ij=1:numel(varargin{2})
% spm_orthviews('Caption', ij, varargin{2}{ij}, varargin{3:end});
%end
end
27 changes: 15 additions & 12 deletions spm_deformations.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
%
% See spm_cfg_deformations.m for more information.
%__________________________________________________________________________
% Copyright (C) 2005-2012 Wellcome Trust Centre for Neuroimaging
% Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging

% John Ashburner
% $Id: spm_deformations.m 5668 2013-10-03 18:34:18Z guillaume $
% $Id: spm_deformations.m 5700 2013-10-17 14:59:50Z guillaume $


[Def,mat] = get_comp(job.comp);
Expand Down Expand Up @@ -406,6 +406,7 @@
end

oM = zeros(4,4);
spm_progress_bar('Init',numel(PI),'Resampling','volumes completed');
for m=1:numel(PI)

% Generate headers etc for output images
Expand All @@ -416,7 +417,7 @@
j_range = 1:size(NI.dat,4);
k_range = 1:size(NI.dat,5);
l_range = 1:size(NI.dat,6);
if ~isempty(num),
if ~isempty(num)
num = sscanf(num,',%d');
if numel(num)>=1, j_range = num(1); end
if numel(num)>=2, k_range = num(2); end
Expand Down Expand Up @@ -448,7 +449,7 @@
NO.mat0 = mat;
NO.mat_intent = 'Aligned';
NO.mat0_intent = 'Aligned';
if isempty(num),
if isempty(num)
out{m} = NO.dat.fname;
else
out{m} = [NO.dat.fname, ',', num2str(num(1))];
Expand All @@ -462,8 +463,8 @@

% Loop over volumes within the file
%----------------------------------------------------------------------
fprintf('%s',nam);
for j=j_range,
%fprintf('%s',nam);
for j=j_range

M0 = NI.mat;
if ~isempty(NI.extras) && isstruct(NI.extras) && isfield(NI.extras,'mat')
Expand All @@ -472,16 +473,16 @@
M0 = M1(:,:,j);
end
end
M = inv(M0);
M = inv(M0);
if ~all(M(:)==oM(:))
% Generate new deformation (if needed)
Y = affine(Def,M);
end
oM = M;
oM = M;
% Write the warped data for this time point
%------------------------------------------------------------------
for k=k_range,
for l=l_range,
for k=k_range
for l=l_range
C = spm_diffeo('bsplinc',single(NI.dat(:,:,:,j,k,l)),intrp);
dat = spm_diffeo('bsplins',C,Y,intrp);
if job.mask
Expand All @@ -491,12 +492,14 @@
spm_smooth(dat,dat,krn); % Side effects
end
NO.dat(:,:,:,j,k,l) = dat;
fprintf('\t%d,%d,%d', j,k,l);
%fprintf('\t%d,%d,%d', j,k,l);
end
end
end
fprintf('\n');
%fprintf('\n');
spm_progress_bar('Set',m);
end
spm_progress_bar('Clear');


%==========================================================================
Expand Down
13 changes: 12 additions & 1 deletion spm_orthviews.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
% Copyright (C) 1996-2013 Wellcome Trust Centre for Neuroimaging

% John Ashburner et al
% $Id: spm_orthviews.m 5542 2013-06-11 17:31:00Z guillaume $
% $Id: spm_orthviews.m 5700 2013-10-17 14:59:50Z guillaume $


% The basic fields of st are:
Expand Down Expand Up @@ -275,6 +275,17 @@
redraw_all

case 'caption'
if ~isnumeric(varargin{1})
varargin{1} = cellstr(varargin{1});
xlh = NaN(numel(varargin{1}),1);
for i=1:numel(varargin{1})
h = spm_orthviews('Caption',i,varargin{1}{i},varargin{3:end});
if ~isempty(h), xlh(i) = h; end
end
varargout{1} = xlh;
return;
end

vh = valid_handles(varargin{1});
nh = numel(vh);

Expand Down
6 changes: 5 additions & 1 deletion spm_orthviews/spm_ov_browser.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
% Copyright (C) 2013 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: spm_ov_browser.m 5585 2013-07-19 15:50:44Z guillaume $
% $Id: spm_ov_browser.m 5700 2013-10-17 14:59:50Z guillaume $


cmd = lower(varargin{1});
Expand Down Expand Up @@ -199,6 +199,10 @@ function browser_profile(hObj,event)
end

plot(hAx,Y);
hold(hAx,'on')
i =round(get(hS,'value'));
plot(hAx,i,Y(i),'r*');
hold(hAx,'off');
ylabel(hAx,sprintf('[%.2f %.2f %.2f]',pos));
st.vols{hC}.browser.fun = @browser_profile;
st.vols{hC}.browser.h = hObj;
Expand Down

0 comments on commit 8cdf53b

Please sign in to comment.