📄 brainnmf.m
字号:
function varargout = brainNMF(varargin)
% brainNMF M-file for nmf2.fig
% NMF2, by itself, creates a new brainNMF or raises the existing
% singleton*.
%
% H = brainNMF returns the handle to a new brainNMF or the handle to
% the existing singleton*.
%
% brainNMF('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in brainNMF.M with the given input arguments.
%
% brainNMF('Property','Value',...) creates a new brainNMF or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before brainNMF_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to brainNMF_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help brainNMF
% Last Modified by Bartlomiej Wilkowski (bw@imm.dtu.dk) 06-Nov-2007, ver.
% 1.4
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @brainNMF_OpeningFcn, ...
'gui_OutputFcn', @brainNMF_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before brainNMF is made visible.
function brainNMF_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to brainNMF (see VARARGIN)
% Choose default command line output for brainNMF
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
addpath('../.');
% UIWAIT makes brainNMF wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = brainNMF_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in plot_thresshold.
function plot_thresshold_Callback(hObject, eventdata, handles)
% hObject handle to plot_thresshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'img')
errordlg('Load file first','Error');
return
end
img = handles.img;
figure(2),
thresshold(1) = str2double(get(handles.lowerThress,'String'));
thresshold(2) = str2double(get(handles.upperThress,'String'));
plotThresshold(img,thresshold)
% --- Executes on button press in plot_spatial.
function plot_spatial_Callback(hObject, eventdata, handles)
% hObject handle to plot_spatial (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'W')
errordlg('Run NMF first','Error');
return
end
W = handles.W;
indx = handles.indx;
%dim = size(handles.img);
plotSlices(W,indx,handles.imgSize)
% --- Executes on button press in rescale.
function rescale_Callback(hObject, eventdata, handles)
% hObject handle to rescale (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of rescale
function set_sources_Callback(hObject, eventdata, handles)
% hObject handle to set_sources (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of set_sources as text
% str2double(get(hObject,'String')) returns contents of set_sources as a double
k = str2double(get(hObject,'String'));
if k<2 || isnan(k)
errordlg('Not valid number','Error');
set(handles.set_sources,'String',3);
return
end
% --- Executes during object creation, after setting all properties.
function set_sources_CreateFcn(hObject, eventdata, handles)
% hObject handle to set_sources (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function set_iterations_Callback(hObject, eventdata, handles)
% hObject handle to set_iterations (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of set_iterations as text
% str2double(get(hObject,'String')) returns contents of set_iterations as a double
iter = str2double(get(hObject,'String'));
if iter<1 || isnan(iter)
errordlg('Not valid number','Error');
set(handles.set_iterations,'String',1000);
return
end
% --- Executes during object creation, after setting all properties.
function set_iterations_CreateFcn(hObject, eventdata, handles)
% hObject handle to set_iterations (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in load_data.
function load_data_Callback(hObject, eventdata, handles)
% hObject handle to load_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%checks if there exist earlier H and W matrices, plotErr and rescaledFlag in <handles> taken from the
%previous NMF calculation. If yes, it removes them.
[fn,pn]=uigetfile('*.img','Analyze file');
if fn~=0
if isfield(handles, 'W')
handles = rmfield(handles, 'W');
end
if isfield(handles, 'H')
handles = rmfield(handles, 'H');
end
if isfield(handles, 'plotErr')
handles = rmfield(handles, 'plotErr');
end
if isfield(handles, 'rescaledFlag')
handles = rmfield(handles, 'rescaledFlag');
end
set(handles.rescale, 'Value', get(handles.rescale, 'Min'));
set(handles.plot_samples,'Enable', 'on');
set(handles.plot_thresshold,'Enable', 'on');
set(handles.run_nmf,'Enable', 'on');
set(handles.plot_spatial,'Enable', 'off');
set(handles.plot_error,'Enable', 'off');
%load([pn fn]);
[img hdr] = ReadAnalyzeImg([pn fn]);
img = reshape((img - hdr.offset).*hdr.scale,hdr.dim');
handles.img = img;
handles.imgSize = size(img);
%set(choose_file,[pn fn])
set(handles.info_text, 'String', 'DATA LOADED for image:');
set(handles.Choose_file, 'String', [pn fn]);
%Also read in .tim file to get frames
[timFileExist]=fileattrib([pn fn(1:end-3) 'tim']);
if timFileExist
[time tmp] = textread([pn fn(1:end-3) 'tim']);
xAxisLabel = 'Time';
else
time = 1:hdr.dim(4);
xAxisLabel = 'Frame';
end
imgMean = mean(img,4);
set(handles.minMean,'String',num2str(min(imgMean(:))));
set(handles.maxMean,'String',num2str(max(imgMean(:))));
set(handles.lowerThress,'String',num2str(min(imgMean(:))));
set(handles.upperThress,'String',num2str(max(imgMean(:))));
handles.time = time;
handles.scanName = hdr.name;
handles.xAxisLabel = xAxisLabel;
% save the structure
guidata(hObject, handles);
end
% --- Executes on button press in plot_samples.
function plot_samples_Callback(hObject, eventdata, handles)
% hObject handle to plot_samples (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'img')
errordlg('Load file first','Error');
return
end
img = handles.img;
time = handles.time;
xAxisLabel = handles.xAxisLabel;
[x y slice frame] = size(img);
img = reshape(img,x*y*slice,frame);
figure(1),plot(time,img(1:1000:end,:)');
xlabel(xAxisLabel), ylabel('Activity'), title('Sample of time curves')
% --- Executes on button press in run_nmf.
function run_nmf_Callback(hObject, eventdata, handles)
% hObject handle to run_nmf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'img')
errordlg('Load file first','Error');
return
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -