www.pudn.com > image_mva_0.rar > image_mva_0.m
function varargout = image_mva_0_0(varargin)
% GUI for Multivariate Analysis of images
% Includes:
% PCA, Simplisma (pure variable method) and MCR (Multivariate Curve Resolution)
% Three types of image classification: 2 unsupervised and 1 supervised
% Basic image processing:
% - cropping, resizing
% - histogram equalization
% - threshold
% - profile plotter
% Filtering:
% - averaging
% - contrast enhancement
% - morphological (opening, closing, eroding, dilation)
% - edge extraction
%
% Works with most types of Image formats:
% JPEG, TIFF, BMP and more (see imread for format types)
% RGB images are converted to grayscale
% Can open MAT files containing variable IMAGES
% Works with TEXT files containing image arrays or individual files
% Works with Kratos VAMAS format XPS photoelectron images *.vms
%
% To run, type:
% image_mva_0
%
% created by K.Artyushkova
% January 2004
% Kateryna Artyushkova
% Postdoctoral Scientist
% Department of Chemical and Nuclear Engineering
% The University of New Mexico
% (505) 277-0750
% kartyush@unm.edu
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @image_mva_0_OpeningFcn, ...
'gui_OutputFcn', @image_mva_0_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 image_mva_0 is made visible.
function image_mva_0_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 image_mva_0 (see VARARGIN)
% Choose default command line output for image_mva_0
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes image_mva_0 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = image_mva_0_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;
% --------------------------------------------------------------------
function open_image_Callback(hObject, eventdata, handles)
% hObject handle to open_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
M = inputdlg('how many Images to open?');
M=str2double(M);
if M==1;
HANDLE = errordlg('More than 1 image has to be open in order to apply MVA','Opening Images');
else
for i=1:M
[filename, pathname] = uigetfile('*.*');
cd(pathname)
image=imread(filename);
[n,m,p]=size(image);
if p==3
image=rgb2gray(image);
data(:,:,i)=double(image);
else
data(:,:,i)=double(image);
end
end
end
handles.or_image=data;
handles.image=data;
handles.N=1;
[n,m,p]=size(data);
set(handles.Min,'string',1);
set(handles.Max,'string',p);
set(handles.current,'string',1);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(data(:,:,1),[min(min(data(:,:,1))) max(max(data(:,:,1)))])
set(handles.current,'string',1);
guidata(hObject,handles)
% --------------------------------------------------------------------
function open_ascii_Callback(hObject, eventdata, handles)
% hObject handle to open_ascii (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
method=questdlg('Are all images in one file?', 'Open text images','Yes','No ','Yes');
if method=='Yes'
[filename, pathname] = uigetfile('*.txt');
cd(pathname)
image=load(filename);
prompt={'X:','Y:','Z:'};
def={'256','256','20'};
dlgTitle='Enter the size of the array';
lineNo=1;
answer=inputdlg(prompt,dlgTitle,lineNo,def);
M=str2double(answer);
[n,m]=size(image);
if m==M(1)
k=M(2)*M(3);
if n==k
image=image';
data=reshape(image,[M(1) M(2) M(3)]);
else
HANDLE = errordlg('The number of elements in array does not correspond to X Y Z values','Opening Images');
end
elseif m==1
k=M(1)*M(2)*M(3);
if n==k
data=reshape(image,[M(1) M(2) M(3)]);
else
HANDLE = errordlg('The number of elements in array does not correspond to X Y Z values','Opening Images');
end
elseif m==M(2)
k=M(1)*M(3);
if n==k
data=reshape(image,[M(1) M(2) M(3)]);
else
HANDLE = errordlg('The number of elements in array does not correspond to X Y Z values','Opening Images');
end
elseif m==M(3)
k=M(1)*M(2);
if n==k
data=reshape(image,[M(1) M(2) M(3)]);
else
HANDLE = errordlg('The number of elements in array does not correspond to X Y Z values','Opening Images');
end
else
end
else
M = inputdlg('how many Images to open?');
M=str2double(M);
if M==1;
HANDLE = errordlg('More than 1 image has to be open in order to apply MVA','Opening Images');
else
prompt={'X:','Y:'};
def={'256','256'};
dlgTitle='Enter the size of image';
lineNo=1;
answer=inputdlg(prompt,dlgTitle,lineNo,def);
N=str2double(answer);
for i=1:M
[filename, pathname] = uigetfile('*.txt');
cd(pathname)
image=load(filename);
[n,m]=size(image);
if m==1
k=N(1)*N(2);
if k==n
data(:,:,i)=reshape(image,[N(1) N(2)]);
else
HANDLE = errordlg('The number of elements in array does not correspond to X Y values','Opening Images');
end
elseif n==N(1)
data(:,:,i)=image;
elseif n==N(2);
data(:,:,i)=image';
else
HANDLE = errordlg('The number of elements in array does not correspond to X Y values','Opening Images');
end
end
end
end
handles.or_image=data;
handles.image=data;
handles.N=1;
[n,m,p]=size(data);
set(handles.Min,'string',1);
set(handles.Max,'string',p);
set(handles.current,'string',1);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(data(:,:,1),[min(min(data(:,:,1))) max(max(data(:,:,1)))])
set(handles.current,'string',1);
guidata(hObject,handles)
% --------------------------------------------------------------------
function open_vms_Callback(hObject, eventdata, handles)
% hObject handle to open_vms (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
M = inputdlg('how many vms images to open?');
M=str2double(M);
if M==1;
HANDLE = errordlg('More than 1 image has to be open in order to apply MVA','Opening Images');
else
for i=1:M
[datafile,datapath] = uigetfile('*.*','Choose a vms file');
cd(datapath)
data(:,:,i)=vms_im_read(datafile,0);
end
end
handles.or_image=data;
handles.image=data;
handles.N=1;
[n,m,p]=size(data);
set(handles.Min,'string',1);
set(handles.Max,'string',p);
set(handles.current,'string',1);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(data(:,:,1),[min(min(data(:,:,1))) max(max(data(:,:,1)))])
set(handles.current,'string',1);
guidata(hObject,handles)
% --------------------------------------------------------------------
function open_mat_Callback(hObject, eventdata, handles)
% hObject handle to open_mat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[datafile,datapath] = uigetfile('*.mat*','Choose a data file');
cd(datapath)
temp=load(datafile);
names=fieldnames(temp);
clear I
I=strmatch('images', names);
a=isempty(I);
if a==1
HANDLE = errordlg('The images in MAT file should be named IMAGES in order to be opened','Opening MAT file');
else
data = getfield(temp,names{I});
handles.image=data;
handles.or_image=data;
handles.N=1;
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(data(:,:,1),[min(min(data(:,:,1))) max(max(data(:,:,1)))])
[n,m,p]=size(data);
set(handles.Min,'string',1);
set(handles.Max,'string',p);
set(handles.current,'string',1);
guidata(hObject,handles)
end
% --------------------------------------------------------------------
function save_spectra_Callback(hObject, eventdata, handles)
% hObject handle to save_spectra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
datapath = uigetdir;
cd(datapath)
images=handles.image;
[filename, pathname] = uiputfile('*.mat', 'Save images as');
save(filename)
% --- Executes during object creation, after setting all properties.
function image_selection_CreateFcn(hObject, eventdata, handles)
% hObject handle to image_selection (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 image_selection_Callback(hObject, eventdata, handles)
% hObject handle to image_selection (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
image=handles.image;
[n,m,p]=size(image);
set(handles.Min,'string',1);
set(handles.Max,'string',p);
step=1/p;
slider_step(1)=step;
slider_step(2)=step;
if step==1;
set(handles.image_selection, 'SliderStep', slider_step, 'Max', 2, 'Min',0,'Value',1)
i=1;
else
set(handles.image_selection, '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
end
set(handles.current,'string',i);
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
if p==1;
imshow(image,[min(min(image)), max(max(image))])
else
imshow(image(:,:,i),[min(min(image(:,:,i))) max(max(image(:,:,i)))])
end
handles.N=i;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function pca_Ncomp_CreateFcn(hObject, eventdata, handles)
% hObject handle to pca_Ncomp (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 pca_Ncomp_Callback(hObject, eventdata, handles)
% hObject handle to pca_Ncomp (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 pca_Ncomp as text
% str2double(get(hObject,'String')) returns contents of pca_Ncomp as a double
Npca=str2double(get(hObject,'String')) ;
handles.Npca=Npca;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function pca_scal_CreateFcn(hObject, eventdata, handles)
% hObject handle to pca_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
function pca_scal_Callback(hObject, eventdata, handles)
% hObject handle to pca_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 pca_scal as text
% str2double(get(hObject,'String')) returns contents of pca_scal as a double
scal=get(hObject,'String');
handles.scal=scal;
guidata(hObject,handles)
% --- Executes on button press in pca_main.
function pca_main_Callback(hObject, eventdata, handles)
% hObject handle to pca_main (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Npca=handles.Npca;
scal=handles.scal;
data=handles.image;
[n,m,p]=size(data);
data=reshape(data,[n*m p]);
h = waitbar(0,'Please wait while PCA is performed...');
if scal=='none'
[Y, lbd, cos2, CC] = pca2(data,Npca);
scores=reshape(Y,[n, m, Npca]);
loads =CC;
else
[Y, lbd, cos2, CC] = pca_mean(data,Npca);
scores=reshape(Y,[n, m, Npca]);
loads =CC;
end
handles.scores=scores;
handles.loads=loads;
close(h)
H.Position=[633 109 274 414];
figure(H)
subplot(2,1,1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(scores(:,:,1),[min(min(scores(:,:,1))) max(max(scores(:,:,1)))])
colormap(gray)
subplot(2,1,2)
plot(loads(:,1))
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function pca_disp_N_CreateFcn(hObject, eventdata, handles)
% hObject handle to pca_disp_N (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 pca_disp_N_Callback(hObject, eventdata, handles)
% hObject handle to pca_disp_N (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 pca_disp_N as text
% str2double(get(hObject,'String')) returns contents of pca_disp_N as a double
Icomp=str2double(get(hObject,'String')) ;
handles.Icomp=Icomp;
guidata(hObject,handles)
% --- Executes on button press in pca_display.
function pca_display_Callback(hObject, eventdata, handles)
% hObject handle to pca_display (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
scores=handles.scores;
loads=handles.loads;
Icomp=handles.Icomp;
H.Position=[633 109 274 414];
figure(H)
subplot(2,1,1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(scores(:,:,Icomp),[min(min(scores(:,:,Icomp))) max(max(scores(:,:,Icomp)))])
subplot(2,1,2)
plot(loads(:,Icomp))
% --------------------------------------------------------------------
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)
datapath = uigetdir;
cd(datapath)
scores=handles.scores;
loads=handles.loads;
image=handles.image;
[filename, pathname] = uiputfile('*.mat', 'Save results as');
save(filename)
% --------------------------------------------------------------------
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 Untitled_3_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function normalize_Callback(hObject, eventdata, handles)
% hObject handle to normalize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
N=handles.N;
[n,p,q]=size(data);
[a,rect]=imcrop(uint8(data(:,:,N)));
for i=1:q;
image_crop(:,:,i)=imcrop(data(:,:,i),rect);
end
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(image_crop(:,:,N),[min(min(image_crop(:,:,N))) max(max(image_crop(:,:,N)))])
handles.image=image_crop;
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 smooth_Callback(hObject, eventdata, handles)
% hObject handle to smooth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
[n,p,q]=size(data);
type=questdlg('How do you want resize the image?','Image resize','Increase', 'Shrink ', 'Increase');
if type=='Increase'
N=inputdlg('Enter N times to increase the image');
N=str2double(N);
for i=1:q;
data_res(:,:,i) = imresize(data(:,:,i),N,'bicubic');
end
else
N=inputdlg('Enter N times to shrink the image');
N=str2double(N);
for i=1:q;
data_res(:,:,i) = imresize(data(:,:,i),1/N,'bicubic');
end
end
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(data_res(:,:,1),[min(min(data_res(:,:,1))) max(max(data_res(:,:,1)))])
handles.image=data_res;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function simp_N_CreateFcn(hObject, eventdata, handles)
% hObject handle to simp_N (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 simp_N_Callback(hObject, eventdata, handles)
% hObject handle to simp_N (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 simp_N as text
% str2double(get(hObject,'String')) returns contents of simp_N as a double
Nsimp=str2double(get(hObject,'String'));
handles.der=0;
handles.simp_N=Nsimp;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function simp_offset_CreateFcn(hObject, eventdata, handles)
% hObject handle to simp_offset (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 simp_offset_Callback(hObject, eventdata, handles)
% hObject handle to simp_offset (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 simp_offset as text
% str2double(get(hObject,'String')) returns contents of simp_offset as a double
offset=str2double(get(hObject,'String')) ;
handles.offset=offset;
guidata(hObject,handles)
% --- Executes on button press in simpl_2nd.
function simpl_2nd_Callback(hObject, eventdata, handles)
% hObject handle to simpl_2nd (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 simpl_2nd
der=get(hObject,'Value');
handles.der=der;
guidata(hObject,handles)
% --- Executes on button press in simplisma_main.
function simplisma_main_Callback(hObject, eventdata, handles)
% hObject handle to simplisma_main (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
offset=handles.offset;
Nsimp=handles.simp_N;
der=handles.der;
images=handles.image;
[n,m,p]=size(images);
data=reshape(images,[n*m p]);
if der==0
[purspec,purint,purity_spec]=simplisma(data,[1:p], offset,Nsimp);
else
data2=invder(data);
[purspec,purint,purity_spec]=simplisma(data,[1:p], offset,Nsimp,data2);
end
pur_images=reshape(purint,[n m Nsimp]);
pur_int=purspec';
H.Position=[633 109 274 414];
figure(H)
subplot(2,1,1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(pur_images(:,:,1),[min(min(pur_images(:,:,1))) max(max(pur_images(:,:,1)))])
subplot(2,1,2)
plot(pur_int(:,1))
handles.pur_images=pur_images;
handles.pur_int=pur_int;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function simp_disp_N_CreateFcn(hObject, eventdata, handles)
% hObject handle to simp_disp_N (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 simp_disp_N_Callback(hObject, eventdata, handles)
% hObject handle to simp_disp_N (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 simp_disp_N as text
% str2double(get(hObject,'String')) returns contents of simp_disp_N as a double
Isimp=str2double(get(hObject,'String')) ;
handles.Isimp=Isimp;
guidata(hObject,handles)
% --- Executes on button press in simp_disp.
function simp_disp_Callback(hObject, eventdata, handles)
% hObject handle to simp_disp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pur_images=handles.pur_images;
pur_int=handles.pur_int;
Isimp=handles.Isimp;
H.Position=[633 109 274 414];
figure(H)
subplot(2,1,1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(pur_images(:,:,Isimp),[min(min(pur_images(:,:,Isimp))) max(max(pur_images(:,:,Isimp)))])
subplot(2,1,2)
plot(pur_int(:,Isimp))
% --------------------------------------------------------------------
function save_simpl_Callback(hObject, eventdata, handles)
% hObject handle to save_simpl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pur_images=handles.pur_images;
pur_int=handles.pur_int;
images=handles.image;
datapath = uigetdir;
cd(datapath)
[filename, pathname] = uiputfile('*.mat', 'Save results as');
save(filename)
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes on button press in mcr_main.
function mcr_main_Callback(hObject, eventdata, handles)
% hObject handle to mcr_main (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
images=handles.image;
[n,m,p]=size(images);
data=reshape(images,[n*m p]);
opt=questdlg('Which intialization you want to use?','MCR','Random ', 'PCA ', 'Simplisma', 'Random ');
if opt=='Random ';
N=inputdlg('Enter the number of components');
Nmcr=str2double(N);
c0=rand(p,Nmcr);
elseif opt=='PCA '
loads=handles.loads;
c0=loads;
else
pur_int=handles.pur_int;
c0=pur_int;
end
opt=questdlg('Do you want to apply nonnegativity to Concentrations?','MCR','Yes', 'No ', 'Yes');
if opt=='Yes'
opt=questdlg('It may take very long time to calculate! Do you still want to apply nonnegativity?','MCR','Yes', 'No ', 'Yes');
if opt=='Yes'
ccon = 2;
else
ccon=0;
end
else
ccon = 0;
end
opt=questdlg('Do you want to apply nonnegativity to Spectra?','MCR','Yes', 'No ', 'Yes');
if opt=='Yes'
opt=questdlg('It may take very long time to calculate! Do you still want to apply nonnegativity?','MCR','Yes', 'No ', 'Yes');
if opt=='Yes'
scon = 2;
else
scon = 0;
end
else
scon = 0;
end
h = waitbar(0,'Please wait while MCR is performed...');
[c,s] = mcr(data',c0,ccon,scon);
close(h)
[n1,p]=size(s);
mcr_images=reshape(s',[n m n1]);
mcr_int=c;
H.Position=[633 109 274 414];
figure(H)
subplot(2,1,1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(mcr_images(:,:,1),[min(min(mcr_images(:,:,1))) max(max(mcr_images(:,:,1)))])
subplot(2,1,2)
plot(mcr_int(:,1))
handles.mcr_images=mcr_images;
handles.mcr_int=mcr_int;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function mcr_disp_N_CreateFcn(hObject, eventdata, handles)
% hObject handle to mcr_disp_N (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 mcr_disp_N_Callback(hObject, eventdata, handles)
% hObject handle to mcr_disp_N (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 mcr_disp_N as text
% str2double(get(hObject,'String')) returns contents of mcr_disp_N as a double
Imcr=str2double(get(hObject,'String')) ;
handles.Imcr=Imcr;
guidata(hObject,handles)
% --- Executes on button press in mcr_disp.
function mcr_disp_Callback(hObject, eventdata, handles)
% hObject handle to mcr_disp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mcr_images=handles.mcr_images;
mcr_int=handles.mcr_int;
Imcr=handles.Imcr;
H.Position=[633 109 274 414];
figure(H)
subplot(2,1,1)
iptsetpref('ImshowAxesVisible', 'on')
imshow(mcr_images(:,:,Imcr),[min(min(mcr_images(:,:,Imcr))) max(max(mcr_images(:,:,Imcr)))])
subplot(2,1,2)
plot(mcr_int(:,Imcr))
% --------------------------------------------------------------------
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_images=handles.mcr_images;
mcr_int=handles.mcr_int;
images=handles.image;
datapath = uigetdir;
cd(datapath)
[filename, pathname] = uiputfile('*.mat', 'Save results as');
save(filename)
% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
image=handles.image;
scores=handles.scores;
loads=handles.loads;
pur_images=handles.pur_images;
pur_int=handles.pur_int;
mcr_images=handles.mcr_images;
mcr_int=handles.mcr_int;
class=handles.C;
datapath = uigetdir;
cd(datapath)
[filename, pathname] = uiputfile('*.mat', 'Save results as');
save(filename)
% --- Executes when figure1 window 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 Edit_Callback(hObject, eventdata, handles)
% hObject handle to Edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Profiler_Callback(hObject, eventdata, handles)
% hObject handle to Profiler (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
profiles(data,'1')
% --------------------------------------------------------------------
function adjust_levels_Callback(hObject, eventdata, handles)
% hObject handle to adjust_levels (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
[m,n,p]=size(data);
for i=1:p
a(i)=max(max(data(:,:,i)));
end
[y,i]=max(a);
k=y/255;
for i=1:p
data_div(:,:,i)=data(:,:,i)./k;
end
handles.image=data_div;
N=handles.N;
axes(handles.axes1);
iptsetpref('ImshowAxesVisible', 'on')
imshow(data_div(:,:,N),[min(min(data_div(:,:,N))) max(max(data_div(:,:,N)))])
guidata(hObject,handles);
% --------------------------------------------------------------------
function histogram_Callback(hObject, eventdata, handles)
% hObject handle to histogram (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
data_eq=histogram(data,'1');
handles.image=data_eq;
guidata(hObject,handles);
% --------------------------------------------------------------------
function threshold_Callback(hObject, eventdata, handles)
% hObject handle to threshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
data_thr=threshold(data,'1');
method=questdlg('Do you want to replace images by thresholded?', 'Replace','Yes','No ','No ');
if method=='Yes'
handles.image_thr=data_thr;
handles.image=data_thr;
else
handles.image_thr=data_thr;
handles.image=data;
end
guidata(hObject,handles);
% --------------------------------------------------------------------
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_image;
axes(handles.axes1)
iptsetpref('ImshowAxesVisible', 'on')
N=handles.N;
imshow(data(:,:,N),[min(min(data(:,:,N))) max(max(data(:,:,N)))])
handles.image=data;
guidata(hObject,handles)
% --------------------------------------------------------------------
function enhance_Callback(hObject, eventdata, handles)
% hObject handle to enhance (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function filter_ave_Callback(hObject, eventdata, handles)
% hObject handle to filter_ave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
[m,n,p]=size(data);
Hsize=inputdlg('Enter the kernel size');
Hsize=str2double(Hsize);
H = fspecial('average',Hsize);
for i=1:p
data_filt(:,:,i) = imfilter(data(:,:,i),H);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function fil_gaussian_Callback(hObject, eventdata, handles)
% hObject handle to fil_gaussian (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
[m,n,p]=size(data);
Hsize=inputdlg('Enter the kernel size');
Hsize=str2double(Hsize);
H = fspecial('gaussian',Hsize);
for i=1:p
data_filt(:,:,i) = imfilter(data(:,:,i),H);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function unsharp_Callback(hObject, eventdata, handles)
% hObject handle to unsharp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
[m,n,p]=size(data);
alpha=inputdlg('Enter the alpha parameter of Laplacian filter (from 0.1-1) (default=0.2)');
alpha=str2double(alpha);
H = fspecial('unsharp',alpha);
for i=1:p
data_filt(:,:,i) = imfilter(data(:,:,i),H);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function edge_Callback(hObject, eventdata, handles)
% hObject handle to edge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.image;
[m,n,p]=size(data);
method=questdlg('Select the method for edge extraction?', 'Edge extraction','sobel ','prewitt','roberts','sobel ');
if method=='sobel '
type='sobel';
elseif method=='prewitt'
type='prewitt';
else
type='roberts';
end
for i=1:p
data_filt(:,:,i) = edge(data(:,:,i),type);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function other_Callback(hObject, eventdata, handles)
% hObject handle to other (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function dilation_Callback(hObject, eventdata, handles)
% hObject handle to dilation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
method=questdlg('Select structuring element', 'Dilation','square','disk ','ball ','square');
if method=='square'
n=inputdlg('Enter the size of box');
n=str2double(n);
se = strel('square',n);
elseif method=='disk '
n=inputdlg('Enter the radius of disk');
n=str2double(n);
se = strel('disk',n);
else
n=inputdlg('Enter the radius of ball');
n=str2double(n);
h=inputdlg('Enter the height of ball');
h=str2double(h);
se = strel('ball',n,h);
end
data=handles.image;
[m,n,p]=size(data);
for i=1:p
data_filt(:,:,i) = imdilate(data(:,:,i),se);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function erosion_Callback(hObject, eventdata, handles)
% hObject handle to erosion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
method=questdlg('Select structuring element', 'Erosion','square','disk ','ball ','square');
if method=='square'
n=inputdlg('Enter the size of box');
n=str2double(n);
se = strel('square',n);
elseif method=='disk '
n=inputdlg('Enter the radius of disk');
n=str2double(n);
se = strel('disk',n);
else
n=inputdlg('Enter the radius of ball');
n=str2double(n);
h=inputdlg('Enter the height of ball');
h=str2double(h);
se = strel('ball',n,h);
end
data=handles.image;
[m,n,p]=size(data);
for i=1:p
data_filt(:,:,i) = imerode(data(:,:,i),se);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function opening_Callback(hObject, eventdata, handles)
% hObject handle to opening (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
method=questdlg('Select structuring element', 'Opening','square','disk ','ball ','square');
if method=='square'
n=inputdlg('Enter the size of box');
n=str2double(n);
se = strel('square',n);
elseif method=='disk '
n=inputdlg('Enter the radius of disk');
n=str2double(n);
se = strel('disk',n);
else
n=inputdlg('Enter the radius of ball');
n=str2double(n);
h=inputdlg('Enter the height of ball');
h=str2double(h);
se = strel('ball',n,h);
end
data=handles.image;
[m,n,p]=size(data);
for i=1:p
data_filt(:,:,i) = imopen(data(:,:,i),se);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --------------------------------------------------------------------
function closing_Callback(hObject, eventdata, handles)
% hObject handle to closing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
method=questdlg('Select structuring element', 'Opening','square','disk ','ball ','square');
if method=='square'
n=inputdlg('Enter the size of box');
n=str2double(n);
se = strel('square',n);
elseif method=='disk '
n=inputdlg('Enter the radius of disk');
n=str2double(n);
se = strel('disk',n);
else
n=inputdlg('Enter the radius of ball');
n=str2double(n);
h=inputdlg('Enter the height of ball');
h=str2double(h);
se = strel('ball',n,h);
end
data=handles.image;
[m,n,p]=size(data);
for i=1:p
data_filt(:,:,i) = imclose(data(:,:,i),se);
end
N=handles.N;
imshow(data_filt(:,:,N),[min(min(data_filt(:,:,N))) max(max(data_filt(:,:,N)))])
handles.image=data_filt;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function class_N_CreateFcn(hObject, eventdata, handles)
% hObject handle to class_N (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 class_N_Callback(hObject, eventdata, handles)
% hObject handle to class_N (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 class_N as text
% str2double(get(hObject,'String')) returns contents of class_N as a double
Nclass=str2double(get(hObject,'String')) ;
handles.Nclass=Nclass;
guidata(hObject,handles)
% --- Executes on button press in classify.
function classify_Callback(hObject, eventdata, handles)
% hObject handle to classify (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
image=handles.image;
[m,n,p]=size(image);
Data=reshape(image, [m*n p]);
method=questdlg('Select classification method', 'Classification','K means','Fuzzy c','MLE ', 'K means');
if method=='K means'
h = waitbar(0,'Please wait while classification is performed...');
Nclass=handles.Nclass;
classes=dckmeans(Data,Nclass);
C=reshape(classes,[m n]);
close(h)
elseif method=='Fuzzy c'
h = waitbar(0,'Please wait while classification is performed...');
Nclass=handles.Nclass;
[classes,U] = dcfuzzy(Data,Nclass);
C=reshape(classes,[m n]);
close(h)
else
C=im_class_MLE(image,'0');
end
H.Position=[563 192 322 297];
figure(H)
imagesc(C)
handles.C=C;
guidata(hObject,handles)
% --- Executes on button press in class_disp.
function class_disp_Callback(hObject, eventdata, handles)
% hObject handle to class_disp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
C=handles.C;
H.Position=[563 192 322 297];
figure(H)
imagesc(C)