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

📄 image_mva_0.m

📁 一个利用Matlab实现PCA(主成分分析)
💻 M
📖 第 1 页 / 共 3 页
字号:

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)




⌨️ 快捷键说明

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