⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brainnmf.asv

📁 非负矩阵分解的matlab代码
💻 ASV
📖 第 1 页 / 共 2 页
字号:
        alg = 'alsobs';
end

[W H] = nmf(abs(img),K,alg,iterations,0);
if (get(handles.rescale,'Value') == get(handles.rescale,'Max'));
    [W H] = rescale(W,H);
    fprintf('Rescaled \n')
end
figure
plot(time,H'), xlabel(xAxisLabel), ylabel('Activity')

handles.indx = indx;%Save indx's for plotting
handles.H = H;
handles.W = W;
guidata(hObject, handles);%save structure

% --- Executes on button press in plot_error.
function plot_error_Callback(hObject, eventdata, handles)
% hObject    handle to plot_error (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, 'H')
    errordlg('Run NMF first','Error');
    return
end
if isfield(handles,'plotErr')
    err = calculatePlotError(handles,1,0);    
else
    err = calculatePlotError(handles,1,1);
    handles.plotErr = err;
end

% function calculates the plot error. If flag plot is set to zero, the
% error plot is not shown. For other positive number, it will be also
% plotted out.
function err = calculatePlotError(handles,plot,calc)

indx = handles.indx;
H = handles.H;
W = handles.W;
x = handles.imgSize(1);
y = handles.imgSize(2);
slice = handles.imgSize(3);
frame = handles.imgSize(4);

if(calc == 0)
    if(plot)
        plotError(handles.plotErr,indx,[x y slice frame]);   
    end
    err = handles.plotErr;
    return
end
img = handles.img;

img = reshape(img,x*y*slice,frame);
img = img(indx,:);%2D with only activ voxels

err = abs(mean(img-W*H,2));
size(err)
if(plot)
    plotError(err,indx,[x y slice frame]);
end

% --- Executes on button press in save_results.
function save_results_Callback(hObject, eventdata, handles)
% hObject    handle to save_results (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, 'H')
    errordlg('Run NMF first','Error');
    return
end
W = handles.W;
H = handles.H;
time = handles.time;
scanName = handles.scanName;

thresshold(1) = str2double(get(handles.lowerThress,'String'));
thresshold(2) = str2double(get(handles.upperThress,'String'));
indx = handles.indx;
iterations = str2double(get(handles.set_iterations,'String'));
imgSize = handles.imgSize;

if isfield(handles,'plotErr')
    plotErr = calculatePlotError(handles,0,0);    
else
    plotErr = calculatePlotError(handles,0,1);    
end

[file,path] = uiputfile('*.mat','Save Results As');

if file~=0
save([path file],'W','H','thresshold','indx','iterations','time','scanName','imgSize','plotErr');
end


function lowerThress_Callback(hObject, eventdata, handles)
% hObject    handle to lowerThress (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 lowerThress as text
%        str2double(get(hObject,'String')) returns contents of lowerThress as a double

if ~isfield(handles, 'img')
    errordlg('Load file first','Error');
    return
end

value = str2double(get(hObject,'String'));
if value<str2double(get(handles.minMean,'String')) | isnan(value) | value>=str2double(get(handles.upperThress,'String'));
    errordlg('Not valid number','Error');
    set(handles.lowerThress,'String',get(handles.minMean,'String'));
    return
end


% --- Executes during object creation, after setting all properties.
function lowerThress_CreateFcn(hObject, eventdata, handles)
% hObject    handle to lowerThress (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 upperThress_Callback(hObject, eventdata, handles)
% hObject    handle to upperThress (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 upperThress as text
%        str2double(get(hObject,'String')) returns contents of upperThress as a double

if ~isfield(handles, 'img')
    errordlg('Load file first','Error');
    return
end

value = str2double(get(hObject,'String'));
if value>str2double(get(handles.maxMean,'String')) | isnan(value) | value<=str2double(get(handles.lowerThress,'String'));
    errordlg('Not valid number','Error');
    set(handles.upperThress,'String',get(handles.maxMean,'String'));
    return
end

% --- Executes during object creation, after setting all properties.
function upperThress_CreateFcn(hObject, eventdata, handles)
% hObject    handle to upperThress (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 selection change in choose_alg.
function choose_alg_Callback(hObject, eventdata, handles)
% hObject    handle to choose_alg (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns choose_alg contents as cell array
%        contents{get(hObject,'Value')} returns selected item from choose_alg


% --- Executes during object creation, after setting all properties.
function choose_alg_CreateFcn(hObject, eventdata, handles)
% hObject    handle to choose_alg (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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 loadResults.
function loadResults_Callback(hObject, eventdata, handles)
% hObject    handle to loadResults (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
import java.lang.*;
if isfield(handles, 'img')
    handles = rmfield(handles, 'img');
end
[fn2,pn2]=uigetfile('*.mat','Load results');
who
if(fn2~=0)
    try
    load([pn2 fn2]);
    handles.W = W;
    size(handles.W)
    handles.H = H;
    handles.indx = indx;
    set(handles.set_iterations,'String', num2str(iterations));
    set(handles.set_sources,'String',num2str(size(handles.H,1)));
    set(handles.lowerThress,'String',num2str(thresshold(1)));
    set(handles.upperThress,'String',num2str(thresshold(2)));
    handles.time = time;
    handles.scanName = scanName;
    handles.imgSize = imgSize;
    handles.plotErr = plotErr;
    
    set(handles.info_text, 'String', 'ONLY RESULTS LOADED for image:');
    set(handles.Choose_file, 'String', handles.scanName);
    
    set(handles.plot_samples,'Enable', 'off');
    set(handles.plot_thresshold,'Enable', 'off');
    set(handles.run_nmf,'Enable', 'off');
    
    guidata(hObject, handles);%save structure
       
    catch
        errordlg('Incorrect format of the MAT file!','Error');
        return
    end
end

% function resultsImageLoad(hObject, eventdata, handles, actionName)
% t1 = 'In order to ';
% t2 = 'the suitable reference image should be loaded. The last location of such file is: [';
% t3 = '] Would you like to load it from here or specify other location of that file?';
% text = [t1 actionName t2 handles.scanName t3];
% 
% button =  questdlg(text,'Load image?','Load from here', 'Load from other location', 'Cancel', 'Load from here');
% if(strcmp(button,'') || strcmp(button,'Cancel'))
%     return
% end
% if(strcmp(button,'Load from here'))
%     [fn,pn]=uigetfile('*.img','Analyze file');
%     if fn~=0
%         %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.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);
% else if(strcmp(button,'Load from other location'))
%         
%     end
% end
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -