📄 four_way_mva.m
字号:
function varargout = four_way_mva(varargin)
% FOUR_WAY_MVA M-file for four_way_mva.fig
% FOUR_WAY_MVA, by itself, creates a new FOUR_WAY_MVA or raises the existing
% singleton*.
%
% H = FOUR_WAY_MVA returns the handle to a new FOUR_WAY_MVA or the handle to
% the existing singleton*.
%
% FOUR_WAY_MVA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FOUR_WAY_MVA.M with the given input arguments.
%
% FOUR_WAY_MVA('Property','Value',...) creates a new FOUR_WAY_MVA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before four_way_mva_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to four_way_mva_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help four_way_mva
% Last Modified by GUIDE v2.5 22-Feb-2005 13:03:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @four_way_mva_OpeningFcn, ...
'gui_OutputFcn', @four_way_mva_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 four_way_mva is made visible.
function four_way_mva_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 four_way_mva (see VARARGIN)
% Choose default command line output for four_way_mva
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes four_way_mva wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = four_way_mva_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 slider movement.
function slider_var1_Callback(hObject, eventdata, handles)
% hObject handle to slider_var1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
data=handles.data;
[n,m,p,q]=size(data);
C1=handles.C1;
C2=handles.C2;
step=1/p;
slider_step(1)=step;
slider_step(2)=step;
set(handles.slider_var1, 'SliderStep', slider_step, 'Max', p, 'Min',0)
i=get(hObject,'Value');
i=round(i);
if i==0
i=1;
elseif i>=p
i=p;
else i=i;
end
C1=i;
set(handles.Cur_1,'string',C1);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data(:,:,C1,C2)), colormap(gray)
handles.C1=C1;
handles.C2=C2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function slider_var1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_var1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on slider movement.
function slider_var2_Callback(hObject, eventdata, handles)
% hObject handle to slider_var2 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
data=handles.data;
[n,m,p,q]=size(data);
C1=handles.C1;
C2=handles.C2;
step=1/q;
slider_step(1)=step;
slider_step(2)=step;
set(handles.slider_var2, 'SliderStep', slider_step, 'Max', q, 'Min',0)
i=get(hObject,'Value');
i=round(i);
if i==0
i=1;
elseif i>=q
i=q;
else i=i;
end
C2=i;
set(handles.Cur_2,'string',C2);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data(:,:,C1,C2)), colormap(gray)
handles.C1=C1;
handles.C2=C2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function slider_var2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_var2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function Cur_1_Callback(hObject, eventdata, handles)
% hObject handle to Cur_1 (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 Cur_1 as text
% str2double(get(hObject,'String')) returns contents of Cur_1 as a double
data=handles.data;
[n,m,p,q]=size(data);
C1=handles.C1;
C2=handles.C2;
C1=str2double(get(hObject,'String')) ;
set(handles.Cur_1,'string',C1);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data(:,:,C1,C2)), colormap(gray)
handles.C1=C1;
handles.C2=C2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Cur_1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Cur_1 (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
function Cur_2_Callback(hObject, eventdata, handles)
% hObject handle to Cur_2 (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 Cur_2 as text
% str2double(get(hObject,'String')) returns contents of Cur_2 as a double
data=handles.data;
[n,m,p,q]=size(data);
C1=handles.C1;
C2=handles.C2;
C2=str2double(get(hObject,'String'));
set(handles.Cur_2,'string',C2);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imagesc(data(:,:,C1,C2)), colormap(gray)
handles.C1=C1;
handles.C2=C2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Cur_2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Cur_2 (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
% --------------------------------------------------------------------
function Load_mat_Callback(hObject, eventdata, handles)
% hObject handle to Load_mat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=lddlgpls;
data=double(data);
handles.data=data;
handles.or_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 File_Callback(hObject, eventdata, handles)
% hObject handle to File (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pca.
function pca_Callback(hObject, eventdata, handles)
% hObject handle to pca (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
N1=handles.N1;
N2=handles.N2;
scal=handles.scal;
data=handles.data;
h = waitbar(0,'Please wait while PCA is performed...');
[n,m,p,q]=size(data);
for i=1:q
images=data(:,:,:,i);
model=imgpca2(images,scal,N1);
scores=double(model.scores);
loads=model.loads;
for j=1:N1
sc1(:,:,i,j)=scores(:,:,j);
l1(:,i,j)=loads(:,j);
end
end
for i=1:N1
model2=imgpca2(sc1(:,:,:,i),scal,N2);
sc2(:,:,:,i)=double(model2.scores);
l2(:,:,i)=model2.loads;
end
close(h)
handles.pca_sc1=sc1;
handles.pca_sc2=sc2;
handles.pca_l1=l1;
handles.pca_l2=l2;
handles.sc1=sc1;
handles.sc2=sc2;
handles.l1=l1;
handles.l2=l2;
t_var1=handles.tit_var1;
t_var2=handles.tit_var2;
figure
for i=1:N2;
subplot(2,N2,i)
imagesc(sc2(:,:,i,1));colormap(gray)
subplot(2,N2,i+N2)
plot(l2(:,i,1)), hline(0,'k--')
axis tight
xlabel(t_var2)
subplot(2,N2,1)
title('PCA results of 1st PC score images from mode 1','Position',[168 -5 9])
end
set(handles.Min_2p,'string',1);
set(handles.Max_2p,'string',q);
set(handles.Cur_2p,'string',1);
handles.model_pca=model;
handles.type='PCA';
guidata(hObject,handles)
function N_1_Callback(hObject, eventdata, handles)
% hObject handle to N_1 (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 N_1 as text
% str2double(get(hObject,'String')) returns contents of N_1 as a double
N1=str2double(get(hObject,'String')) ;
handles.N1=N1;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function N_1_CreateFcn(hObject, eventdata, handles)
% hObject handle to N_1 (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
function N_2_Callback(hObject, eventdata, handles)
% hObject handle to N_2 (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 N_2 as text
% str2double(get(hObject,'String')) returns contents of N_2 as a double
N2=str2double(get(hObject,'String')) ;
handles.N2=N2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function N_2_CreateFcn(hObject, eventdata, handles)
% hObject handle to N_2 (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
function scal_Callback(hObject, eventdata, handles)
% hObject handle to scal (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 scal as text
% str2double(get(hObject,'String')) returns contents of scal as a double
scal=get(hObject,'String');
handles.scal=scal;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function scal_CreateFcn(hObject, eventdata, handles)
% hObject handle to scal (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 button press in simplisma.
function simplisma_Callback(hObject, eventdata, handles)
% hObject handle to simplisma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
N1=handles.N1;
N2=handles.N2;
data=handles.data;
[n,m,p,q]=size(data);
for i=1:q
images=data(:,:,:,i);
data1=reshape(images,[n*m p]);
[purspec,purint,purity_spec]=simplisma_4w(data1,[1:p], 5, N1);
pur_images=reshape(purint,[n m N1]);
pur_int=purspec';
for j=1:N1
sc1(:,:,i,j)=pur_images(:,:,j);
l1(:,i,j)=pur_int(:,j);
end
end
for i=1:N1
data2=sc1(:,:,:,i);
[n2,m2,p2]=size(data2);
data3=reshape(data2,[n2*m2 p2]);
[purspec2,purint2,purity_spec]=simplisma_4w(data3,[1:p2], 5, N2);
pur_images2=reshape(purint2,[n2 m2 N2]);
pur_int2=purspec2';
sc2(:,:,:,i)=pur_images2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -