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

📄 four_way_mva.m

📁 GUI for Multivariate Image Analysis of 4-dimensional data (Matlab Code)
💻 M
📖 第 1 页 / 共 3 页
字号:
[n,m,p,q]=size(data);
data2=reshape(data,[n*m, p,q]);
options=tucker('options');
options.constraints{1}.nonnegativity=1;
options.constraints{2}.nonnegativity=1;
options.constraints{3}.nonnegativity=1;
options.constraints{4}.nonnegativity=1;
options.display='off';
options.plots='none';
options.constraints{1}.orthogonal=0;
options.constraints{2}.orthogonal=0;
options.constraints{3}.orthogonal=0;
options.constraints{4}.orthogonal=0;
N=inputdlg('Enter the number of components');  
N=str2double(N);
model=tucker(data2,[N N N],options);
scores=reshape(model.loads{1},[n m N]);
loads1=model.loads{2};
loads2=model.loads{3};
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
H.Position=[521 187 262 521];
figure (H)
subplot(2,1,1)
plot(loads1)
hline(0,'k--')
axis tight
xlabel(t_var1)
subplot(2,1,2)
plot(loads2)
hline(0,'k--')
axis tight
xlabel(t_var2)
H.Position=[257 186 257 523];
figure(H)
if N<=3
    for i=1:N
    subplot(N,1,i)
    imagesc(scores(:,:,i));colormap(gray)
    end
elseif N==4
    for i=1:N
        subplot(2,2,i)
        imagesc(scores(:,:,i));colormap(gray)
    end
else
    [a,b,c]=size(scores);
im=reshape(scores,[a b 1 c]);
montage(im,colormap(gray))
end
handles.type3='tucker';
handles.model_tucker=model;
handles.scores_tucker=scores;
handles.loads1_tucker=loads1;
handles.loads2_tucker=loads2;
handles.scores3=scores;
handles.loads1_3=loads1;
handles.loads2_3=loads2;
guidata(hObject,handles)



% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function save_mat_Callback(hObject, eventdata, handles)
% hObject    handle to save_mat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
svdlgpls(data,'save data into mat file or workspace')
% --------------------------------------------------------------------
function save_pca_Callback(hObject, eventdata, handles)
% hObject    handle to save_pca (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

pca_model.sc1=handles.pca_sc1;
pca_model.sc2=handles.pca_sc2;
pca_model.l1=handles.pca_l1;
pca_model.l2=handles.pca_l2;
svdlgpls(pca_model,'save PCA model into mat file or workspace')

% --------------------------------------------------------------------
function save_simplisma_Callback(hObject, eventdata, handles)
% hObject    handle to save_simplisma (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

simp_model.sc1=handles.simp_sc1;
simp_model.sc2=handles.simp_sc2;
simp_model.l1=handles.simp_l1;
simp_model.l2=handles.simp_l2;
svdlgpls(simp_model,'save Simplisma model into mat file or workspace')

% --------------------------------------------------------------------
function save_mcr_Callback(hObject, eventdata, handles)
% hObject    handle to save_mcr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
mcr_model.sc1=handles.mcr_sc1;
mcr_model.sc2=handles.mcr_sc2;
mcr_model.l1=handles.mcr_l1;
mcr_model.l2=handles.mcr_l2;
svdlgpls(mcr_model,'save MCR model into mat file or workspace')

% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function shrink_Callback(hObject, eventdata, handles)
% hObject    handle to shrink (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
N=inputdlg('Enter N times to shrink the image');  
N=str2double(N);
[n,m,p,q]=size(data);
data_res(:,:,1,1) = imresize(data(:,:,1,1),1/N,'bicubic');
data_res(:,:,p,q) = imresize(data(:,:,p,q),1/N,'bicubic');
for i=1:p
    for j=1:q
        data_res(:,:,i,j) = imresize(data(:,:,i,j),1/N,'bicubic');
    end
end
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data_res(:,:,1,1)), colormap(gray)
handles.data=data_res;
handles.data_res=data_res;
guidata(hObject,handles)

    


% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function undo_Callback(hObject, eventdata, handles)
% hObject    handle to undo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.or_data;
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data(:,:,1,1)), colormap(gray)
handles.data=data;
guidata(hObject,handles)


% --------------------------------------------------------------------
function crop_Callback(hObject, eventdata, handles)
% hObject    handle to crop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
[n,m,p,q]=size(data);
figure(1)
P=round(p/2);
Q=round(q/2);
[a,rect]=imcrop(uint8(data(:,:,P,Q)));
data_crop(:,:,1,1)=imcrop(data(:,:,1,1),rect);
data_crop(:,:,p,q)=imcrop(data(:,:,p,q),rect);
for i=1:p
    for j=1:q
        data_crop(:,:,i,j)=imcrop(data(:,:,i,j),rect);
    end
end
close(1)
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data_crop(:,:,P,Q)), colormap(gray)
handles.data=data_crop;
handles.data_crop=data_crop;
guidata(hObject,handles)


% --------------------------------------------------------------------
function adjust_max_Callback(hObject, eventdata, handles)
% hObject    handle to adjust_max (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
[m,n,p,q]=size(data);
for i=1:p
    for j=1:q
        a(i,j)=max(max(data(:,:,i,j)));
    end
end
y=max(max(a))

k=y/255;
data_div(:,:,1,1)=data(:,:,1,1)./k;
data_div(:,:,p,q)=data(:,:,p,q)./k;
for i=1:p
    for j=1:q
        data_div(:,:,i,j)=data(:,:,i,j)./k;
    end
end

iptsetpref('ImshowAxesVisible', 'on')
imagesc(data_div(:,:,1,1)), colormap(gray)
handles.data=data_div;
handles.data_div=data_div;
guidata(hObject,handles);



% --------------------------------------------------------------------
function open_images_Callback(hObject, eventdata, handles)
% hObject    handle to open_images (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname]=uigetfiles('*.*','Open images');
cd(pathname)
[N,M]=size(filename);
a=str2double(inputdlg('Enter number of Channels'));  
b=str2double(inputdlg('Enter number of depth slices'));  
M1=a*b;
if M1==M
else 
    HANDLE = errordlg('The number of images opened does not match # of channels and depths','Opening Images');
end
image=imread(char(filename(:,1)));
data(:,:,1,1)=double(image);
data(:,:,a,b)=double(image);
for i=1:b
    k=i*a;
    for j=(k-a+1):k
    image=imread(char(filename(:,j)));
    r=j-(i-1)*a;
    data(:,:,r,i)=double(image);
    end
end
handles.data=data;
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data(:,:,1,1)), colormap(gray)
[n,m,p,q]=size(data);
set(handles.Min_1,'string',1);
set(handles.Max_1,'string',p);
set(handles.Cur_1,'string',1);
set(handles.Min_2,'string',1);
set(handles.Max_2,'string',q);
set(handles.Cur_2,'string',1);
prompt={'Variable 1:','Variable2:'};
def={'Wavelength','Depth'};
dlgTitle='Enter the title of variables';
lineNo=1;
answer=inputdlg(prompt,dlgTitle,lineNo,def);
set(handles.title_var1,'string',answer{1});
set(handles.title_var2,'string',answer{2});
handles.tit_var1=answer{1};
handles.tit_var2=answer{2};
handles.C1=1;
handles.C2=1;
guidata(hObject,handles)


% --------------------------------------------------------------------
function flip_mode_Callback(hObject, eventdata, handles)
% hObject    handle to flip_mode (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
[n,m,p,q]=size(data);

for i=1:p
    data_flip(:,:,:,i)=data(:,:,i,:);
end
handles.data=data_flip;
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data_flip(:,:,1,1)), colormap(gray)
[n,m,p,q]=size(data_flip);
set(handles.Min_1,'string',1);
set(handles.Max_1,'string',p);
set(handles.Cur_1,'string',1);
set(handles.Min_2,'string',1);
set(handles.Max_2,'string',q);
set(handles.Cur_2,'string',1);
handles.C1=1;
handles.C2=1;
t_var2=handles.tit_var1;
t_var1=handles.tit_var2;
set(handles.title_var1,'string',t_var1);
set(handles.title_var2,'string',t_var2);
handles.tit_var1=t_var1;
handles.tit_var2=t_var2;
guidata(hObject,handles)


% --------------------------------------------------------------------
function Profile_1_Callback(hObject, eventdata, handles)
% hObject    handle to Profile_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
[n,m,p,q]=size(data);
C1=handles.C1;
C2=handles.C2;
images=data(:,:,:,C2);
profiles(images,'1')  

% --------------------------------------------------------------------
function profile_2_Callback(hObject, eventdata, handles)
% hObject    handle to profile_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.data;
[n,m,p,q]=size(data);
C1=handles.C1;
C2=handles.C2;
images=data(:,:,C1,:);
images=reshape(images,[n,m,q]);
profiles(images,'1')  

% --------------------------------------------------------------------
function Analyze_Callback(hObject, eventdata, handles)
% hObject    handle to Analyze (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function save_parafac_Callback(hObject, eventdata, handles)
% hObject    handle to save_parafac (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
parafac_model=handles.parafac_model;
svdlgpls(parafac_model,'save Parafac model into mat file or workspace')

% --------------------------------------------------------------------
function save_tucker_Callback(hObject, eventdata, handles)
% hObject    handle to save_tucker (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
model_tucker=handles.model_tucker;
svdlgpls(model_tucker,'save Parafac model into mat file or workspace')


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

type=handles.type3;
scores=handles.scores3;
loads1=handles.loads1_3;
loads2=handles.loads2_3;
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
N=str2double(get(hObject,'String')) ;
H.Position=[521 187 262 521];
figure (H)
subplot(3,1,1)
imagesc(scores(:,:,N));colormap(gray)
subplot(3,1,2)
plot(loads1(:,N))
axis tight
hline(0,'k--')
xlabel(t_var1)
subplot(3,1,3)
plot(loads2(:,N))
hline(0,'k--')
axis tight
xlabel(t_var2)
subplot(3,1,1)
title(['The ', type, ' results for component #', num2str(N)])



% --- Executes during object creation, after setting all properties.
function Ncomp_3way_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Ncomp_3way (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in disp_res_3way.
function disp_res_3way_Callback(hObject, eventdata, handles)
% hObject    handle to disp_res_3way (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 disp_res_3way contents as cell array
%        contents{get(hObject,'Value')} returns selected item from disp_res_3way
val = get(hObject,'Value');
switch val
case 2
scores=handles.scores_parafac;
loads1=handles.loads1_parafac;
loads2=handles.loads2_parafac;
handles.type3='parafac';

case 3
scores=handles.scores_tucker;
loads1=handles.loads1_tucker;
loads2=handles.loads2_tucker;
handles.type3='tucker';

case 4
scores=handles.scores_mcr3;
loads1=handles.loads1_mcr3;
loads2=handles.loads2_mcr3;
handles.type3='MCR';

end
handles.scores3=scores;
handles.loads1_3=loads1;
handles.loads2_3=loads2;

guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function disp_res_3way_CreateFcn(hObject, eventdata, handles)
% hObject    handle to disp_res_3way (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


⌨️ 快捷键说明

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