📄 shiyan4.m
字号:
function varargout = shiyan4(varargin)
% SHIYAN4 M-file for shiyan4.fig
% SHIYAN4, by itself, creates a new SHIYAN4 or raises the existing
% singleton*.
%
% H = SHIYAN4 returns the handle to a new SHIYAN4 or the handle to
% the existing singleton*.
%
% SHIYAN4('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SHIYAN4.M with the given input arguments.
%
% SHIYAN4('Property','Value',...) creates a new SHIYAN4 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before shiyan4_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to shiyan4_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 shiyan4
% Last Modified by GUIDE v2.5 02-Dec-2007 23:01:15
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @shiyan4_OpeningFcn, ...
'gui_OutputFcn', @shiyan4_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 shiyan4 is made visible.
function shiyan4_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 shiyan4 (see VARARGIN)
% Choose default command line output for shiyan4
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes shiyan4 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = shiyan4_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 button press in open1.
function open1_Callback(hObject, eventdata, handles)
% hObject handle to open1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path]=uigetfile('*.jpg;*.tif');
if isequal(file,0)
disp('User selected Cancel')
else
filename=fullfile(path,file);
end
picture=imread(filename);
%%%显示RGB分量
[r c d]=size(picture);
red(:,:,1)=picture(:,:,1);
red(:,:,2)=zeros(r,c);
red(:,:,3)=zeros(r,c);
red=uint8(red);
axes(handles.R)
set(handles.R, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(red);
hold on
green(:,:,2)=picture(:,:,2);
green(:,:,1)=zeros(r,c);
green(:,:,3)=zeros(r,c);
green=uint8(green);
axes(handles.G)
set(handles.G, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(green);
hold on
blue(:,:,3)=picture(:,:,3);
blue(:,:,1)=zeros(r,c);
blue(:,:,2)=zeros(r,c);
blue=uint8(blue);
axes(handles.B)
set(handles.B, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(blue);
hold on
%%显示HSI分量
rgb1=im2double(picture);
red=rgb1(:,:,1);
green=rgb1(:,:,2);
blue=rgb1(:,:,3);
for i=1:r
for j=1:c
a=[red(i,j),green(i,j),blue(i,j)];
min1=min(a);
max1=max(a);
S(i,j)=max1-min1;
I(i,j)=(red(i,j)+green(i,j)+blue(i,j))/3;
if(blue(i,j)>green(i,j))
H(i,j)=2*pi-acos(((red(i,j)-green(i,j))+(red(i,j)-blue(i,j)))/((2*sqrt((red(i,j)-green(i,j))^2+(red(i,j)-blue(i,j))*(green(i,j)-blue(i,j))))+eps));
else
H(i,j)=acos(((red(i,j)-green(i,j))+(red(i,j)-blue(i,j)))/((2*sqrt((red(i,j)-green(i,j))^2+(red(i,j)-blue(i,j))*(green(i,j)-blue(i,j))))+eps));
end
if(S(i,j)==0)
H(i,j)=0;
end
end
end
axes(handles.H)
set(handles.H, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(H);
hold on
axes(handles.S)
set(handles.S, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(S);
hold on
axes(handles.I)
set(handles.I, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(I);
hold on
% --- Executes on button press in open2.
function open2_Callback(hObject, eventdata, handles)
% hObject handle to open2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path]=uigetfile('*.jpg;*.tif');
if isequal(file,0)
disp('User selected Cancel')
else
filename=fullfile(path,file);
end
handles.my_file=filename;
guidata(hObject,handles);
picture=imread(filename);
[r c d]=size(picture);
axes(handles.yuantu)
set(handles.yuantu, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(picture);
hold on
% --- Executes on selection change in select.
function select_Callback(hObject, eventdata, handles)
% hObject handle to select (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 select contents as cell array
% contents{get(hObject,'Value')} returns selected item from select
%type=get(handles.select,'string');
%handles.my_type=type;
%guidata(hObject,handles);
val = get(hObject,'Value');
%string_list = get(hObject,'String');
%selected_string = string_list{val};
handles.my_type=val;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function select_CreateFcn(hObject, eventdata, handles)
% hObject handle to select (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
function mobanshu_Callback(hObject, eventdata, handles)
% hObject handle to mobanshu (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 mobanshu as text
% str2double(get(hObject,'String')) returns contents of mobanshu as a double
% --- Executes during object creation, after setting all properties.
function mobanshu_CreateFcn(hObject, eventdata, handles)
% hObject handle to mobanshu (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 button press in xianshi.
function xianshi_Callback(hObject, eventdata, handles)
% hObject handle to xianshi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename=handles.my_file;
type=handles.my_type;
m=str2double(get(handles.mobanshu,'String'));
picture=imread(filename);
[r c d]=size(picture);
switch type
case 1
B=my_mean1(filename,m);
axes(handles.bianhuan)
set(handles.bianhuan, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(B);
hold on
case 2
B=my_median1(filename,m);
axes(handles.bianhuan)
set(handles.bianhuan, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(B);
hold on
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -