📄 spm_mf_box.m
字号:
if (strcmp(v,'No sort')) handles.permutation = 1:size(handles.mfbss.A,2);else [d,handles.permutation] = sort(-handles.mfbss.reliability.(v(9:end)));endset(handles.time_pos,'Value',1);set(handles.comp_pos,'Value',1);handles = redraw_all(handles);guidata(hObject,handles);% --- Executes on selection change in display_opts.function display_opts_Callback(hObject,eventdata,handles)handles = redraw_all(handles);guidata(hObject,handles);% --- Executes during object creation, after setting all properties.function sort_comp_CreateFcn(hObject,eventdata,handles)if (ispc&&(isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor')))) set(hObject,'BackgroundColor','white');end% --- Executes during object creation, after setting all properties.function display_opts_CreateFcn(hObject,eventdata,handles)if (ispc&&(isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor')))) set(hObject,'BackgroundColor','white');end% --- Executes on selection change in algo_preprocess.function algo_preprocess_Callback(hObject,eventdata,handles)% --- Executes during object creation, after setting all properties.function algo_preprocess_CreateFcn(hObject,eventdata,handles)if (ispc&&(isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor')))) set(hObject,'BackgroundColor','white');end% --- Executes on selection change in algo_reliability.function algo_reliability_Callback(hObject,eventdata,handles)function algo_reliability_CreateFcn(hObject,eventdata,handles)if (ispc&&(isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor')))) set(hObject,'BackgroundColor','white');endfunction algo_postprocess_Callback(hObject,eventdata,handles)% --- Executes during object creation, after setting all properties.function algo_postprocess_CreateFcn(hObject,eventdata,handles)if (ispc&&(isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor')))) set(hObject,'BackgroundColor','white');end% --- Executes on button press in export_mask.function export_mask_Callback(hObject,eventdata,handles)mfbox_databackend('export_mask',handles.private,handles.mfbss.mask);guidata(hObject,handles);% --- Executes on button press in export_result.function export_result_Callback(hObject,eventdata,handles)contents = get(handles.plot_type,'String');if (isempty(contents)), t = '';else t = contents{get(handles.plot_type,'Value')};endvt = get(handles.time_pos,'Value');vc = get(handles.comp_pos,'Value');if (~isempty(handles.permutation)), vc = handles.permutation(vc); endd = zeros(size(handles.mfbss.bg));if (strcmp(t,'Processed Data')) sgr = size(handles.mfbss.grid); sm = size(handles.mfbss.mask); g = mat2cell(min(repmat(sm',1,sgr(2)),max(ones(sgr), ... round(handles.mfbss.grid))),ones(1,sgr(1)),sgr(2)); d(unique(sub2ind(sm,g{:}))) = handles.mfbss.S.dat(:,handles.mfbss.S.map(vt,vc));else sgr = size(handles.mfbss.grid); sm = size(handles.mfbss.mask); g = mat2cell(min(repmat(sm',1,sgr(2)),max(ones(sgr), ... round(handles.mfbss.grid))),ones(1,sgr(1)),sgr(2)); d(unique(sub2ind(sm,g{:}))) = handles.mfbss.ppS.dat(:,handles.mfbss.ppS.map(vt,vc));endif (isempty(handles.filenames)), handles.filenames = char(ones(1,0)*' '); endhandles.filenames = mfbox_databackend('export_result', ... handles.private,d,handles.filenames(1,:));guidata(hObject,handles);% --- Executes on button press in run_estimate.function run_estimate_Callback(hObject,eventdata,handles)if ((get(handles.keeppre,'Value')==0)||(isempty(handles.mfbss.X))||(isstruct(handles.mfbss.X))) if (isstruct(handles.mfbss.X)) X = handles.mfbss.X; mask = handles.mfbss.mask; else X = handles.sequence; mask = true(X.dim); end mm = sum(mask(:)); s = [X.dim,X.timesteps]; C = zeros(X.timesteps); m = zeros(1,X.timesteps); Y = zeros(sum(mask(:)),s(end)); for i=1:X.timesteps ly = reshape(mfbox_databackend('getdata',X,i),[],1); Y(:,i) = ly(mask,:); end for i=1:X.timesteps for j=(i+1):X.timesteps v = Y(:,[i,j]); if (i==(j-1)) C(i,i) = sum(v(:,1).^2); m(i) = sum(v(:,1)); end C(i,j) = v(:,1)'*v(:,2); C(j,i) = C(i,j); if ((i==(j-1))&&(j==X.timesteps)) C(j,j) = sum(v(:,2).^2); m(j) = sum(v(:,2)); end end end m = m/mm; C = C/(mm-1)-m'*m;else mm = sum(handles.mfbss.mask(:)); X = single(handles.mfbss.X); s = size(X); X = reshape(X,prod(s(1:(end-1))),s(end)); sgr = size(handles.mfbss.grid); sm = size(handles.mfbss.mask); g = mat2cell(min(repmat(sm',1,sgr(2)),max(ones(sgr), ... round(handles.mfbss.grid))),ones(1,sgr(1)),sgr(2)); mask = handles.mfbss.mask(sub2ind(sm,g{:})); if (any(~mask)), X = X(mask,:); end C = double(cov(X));end[E,D] = eig(C);D = -sort(-diag(D));mdlcomp = max(min(mfbox_getmdl(D,mm),s(end)),1);v = fieldnames(handles.mfbss.params);for i=1:length(v) if (isfield(handles.mfbss.params.(v{i}),'numComponents')) handles.mfbss.params.(v{i}).numComponents = mdlcomp; endendguidata(hObject,handles);% --- Executes on button press in export_ic.function export_ic_Callback(hObject, eventdata, handles)vt = get(handles.time_pos,'Value');vc = get(handles.comp_pos,'Value');if (~isempty(handles.permutation)), vc = handles.permutation(vc); endcontents = get(handles.plot_type,'String');if (isempty(contents)), return;else t = contents{get(handles.plot_type,'Value')};end[st,re] = getdisplayopts(handles.display_opts);[f,d] = uiputfile('*.svg','Select output file ...');if (isempty(f)), return; endtmpfile = fullfile(d,f);prgs = mfbox_progress([],'title','Plot','string','Generating plot','progress',[1,4]);drawnow;[bg,handles.private] = mfbox_databackend('getbg',handles.private);[atlas,handles.private] = mfbox_databackend('getatlas',handles.private);mfbox_progress(prgs,'string','Generating plot','progress',[2,4]);name = '';if (strcmp(t,'Processed Data')) tc = handles.mfbss.A(:,vc)'; [ic,handles.private] = mfbox_databackend('getic',handles.private, ... handles.mfbss.S.dat(:,handles.mfbss.S.map(vt,vc)), ... handles.mfbss.grid(:,handles.mfbss.S.mask),handles.mfbss.mask);else tc = handles.mfbss.ppA(:,vc)'; [ic,handles.private] = mfbox_databackend('getic',handles.private, ... handles.mfbss.ppS.dat(:,handles.mfbss.ppS.map(vt,vc)), ... handles.mfbss.grid(:,handles.mfbss.ppS.mask),handles.mfbss.mask); if (isfield(handles.mfbss.ppS,'tag')), name = handles.mfbss.ppS.tag{vc}; endendmfbox_progress(prgs,'string','Generating plot','progress',[3,4]);mfbox_progress(prgs,'close',[]);tc = {tc,handles.mfbss.timeline};if (~isempty(handles.mfbss.design)) sd = size(handles.mfbss.design); for i=1:sd(2) tc{2+i} = interp1(linspace(handles.mfbss.timeline(1),handles.mfbss.timeline(end),sd(1)), ... handles.mfbss.design(:,i),handles.mfbss.timeline)'; endendf = fopen(tmpfile,'w');dat = mfbox_plotic(ic,tc, ... sprintf('%s analysis component %d %s',handles.mfbss.name,vc,name), ... {st,re},bg,atlas,1);fwrite(f,dat,'char');fclose(f);guidata(hObject,handles);% --- Executes on button press in plot.function plot_Callback(hObject,eventdata,handles)vt = get(handles.time_pos,'Value');vc = get(handles.comp_pos,'Value');if (~isempty(handles.permutation)), vc = handles.permutation(vc); endcontents = get(handles.plot_type,'String');if (isempty(contents)), return;else t = contents{get(handles.plot_type,'Value')};end[st,re] = getdisplayopts(handles.display_opts);prgs = mfbox_progress([],'title','Plot','string','Generating plot','progress',[1,4]);drawnow;[bg,handles.private] = mfbox_databackend('getbg',handles.private);[atlas,handles.private] = mfbox_databackend('getatlas',handles.private);mfbox_progress(prgs,'string','Generating plot','progress',[2,4]);aviplot = false;name = '';map = [];if (strcmp(t,'Processed Data')) map = handles.mfbss.S.map(:,vc); cs = unique(map)';else map = handles.mfbss.ppS.map(:,vc); cs = unique(map)';endic = {};if (length(cs)>1) a = questdlg(sprintf( ... 'Generate Movie from all frames in this component?\n'), ... 'Movie','Yes','No','Yes'); if (strcmp(a,'Yes')), aviplot = true; endendif (~aviplot) if (strcmp(t,'Processed Data')) cs = handles.mfbss.S.map(vt,vc); else cs = handles.mfbss.ppS.map(vt,vc); endendfor comp=cs if (strcmp(t,'Processed Data')) tc = handles.mfbss.A(:,vc)'; cic = handles.mfbss.S.dat(:,comp); if (~all(cic(:)==0)) [ic{end+1},handles.private] = mfbox_databackend('getic',handles.private, ... cic,handles.mfbss.grid(:,handles.mfbss.S.mask),handles.mfbss.mask); end else tc = handles.mfbss.ppA(:,vc)'; cic = handles.mfbss.ppS.dat(:,comp); if (~all(cic(:)==0)) [ic{end+1},handles.private] = mfbox_databackend('getic',handles.private, ... cic,handles.mfbss.grid(:,handles.mfbss.ppS.mask),handles.mfbss.mask); end if (isfield(handles.mfbss.ppS,'tag')), name = handles.mfbss.ppS.tag{vc}; end endendmfbox_progress(prgs,'string','Generating plot','progress',[3,4]);mfbox_progress(prgs,'close',[]);tc = {tc,handles.mfbss.timeline};if (~isempty(handles.mfbss.design)) sd = size(handles.mfbss.design); for i=1:sd(2) tc{2+i} = interp1(linspace(handles.mfbss.timeline(1),handles.mfbss.timeline(end),sd(1)), ... handles.mfbss.design(:,i),handles.mfbss.timeline)'; endendif (aviplot) p = cell(1,length(ic)); fh = 0; for i=1:length(ic) mtc = tc(1:2); mtc{3} = map==cs(i); p{i} = mfbox_plotic(ic{i},mtc, ... sprintf('%s analysis component %d %s',handles.mfbss.name,vc,name), ... {st,re},bg,atlas,{fh,2}); fh = p{i}; M(i) = getframe(fh); end close(fh); figure; run = true; while (run) movie(M,5,1); a = questdlg(sprintf('Repeat or save?\n'), ... 'Movie','Yes','Save','No','Yes'); run = strcmp(a,'Yes'); if (strcmp(a,'Save')) [f,d] = uiputfile('*.avi','Select output file ...'); if (isempty(f)), return; end tmpfile = fullfile(d,f); movie2avi(M,tmpfile); run = false; end endelse mfbox_plotic(ic{1},tc, ... sprintf('%s analysis component %d %s',handles.mfbss.name,vc,name), ... {st,re},bg,atlas,2);endguidata(hObject,handles);% --- Executes on button press in keeppre.function keeppre_Callback(hObject,eventdata,handles)if (get(hObject,'Value')==1) set(handles.algo_preprocess,'Enable','off'); set(handles.run_pre,'Enable','off');else set(handles.algo_preprocess,'Enable','on'); set(handles.run_pre,'Enable','on');end% --- Executes on button press in compare_ics.function compare_ics_Callback(hObject,eventdata,handles)mfbox_tool_compare_run(handles.mfbss);% --- Executes on button press in open_help.function open_help_Callback(hObject,eventdata,handles)mfd = fileparts(which('spm_mf_box'));dirs = {fullfile(mfd,'doc','html'),'/usr/local/share/mfbox/html','/usr/share/mfbox/html'};r = true; i = 1;while (r&&(i<=length(dirs))) d = dirs{i}; f = fullfile(d,'index.html'); if (exist(f)) r = false; web(sprintf('file://%s',f),'-helpbrowser'); end i = i+1;end% --- Executes on button press in load_params.function load_params_Callback(hObject,eventdata,handles)nSeq = handles.sequence.timesteps;p = {'name','params','rel_name','rel_params','pos_name','pos_params'};pp = {'pre_name','pre_params'};[mfbss,handles.params_filename] = mfbox_databackend('load_params', ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -