📄 shiyan2.m
字号:
function varargout = shiyan2(varargin)
% SHIYAN2 M-file for shiyan2.fig
% SHIYAN2, by itself, creates a new SHIYAN2 or raises the existing
% singleton*.
%
% H = SHIYAN2 returns the handle to a new SHIYAN2 or the handle to
% the existing singleton*.
%
% SHIYAN2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SHIYAN2.M with the given input arguments.
%
% SHIYAN2('Property','Value',...) creates a new SHIYAN2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before shiyan2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to shiyan2_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 shiyan2
% Last Modified by GUIDE v2.5 30-Nov-2007 23:08:49
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @shiyan2_OpeningFcn, ...
'gui_OutputFcn', @shiyan2_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 shiyan2 is made visible.
function shiyan2_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 shiyan2 (see VARARGIN)
% Choose default command line output for shiyan2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes shiyan2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = shiyan2_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 open_file1.
function open_file1_Callback(hObject, eventdata, handles)
% hObject handle to open_file1 (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);
[r,c]=size(picture);
axes(handles.huiduxianshi1)
set(handles.huiduxianshi1, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(picture);
hold on;
%直方图显示程序
%picture1=picture+1;
A=zeros(1,256);
for i=1:r
for j=1:c
a=picture(i,j);
if(a>257)
a=256;
A(1,a)=A(1,a)+1;
elseif(a==0)
a=1;
A(1,a)=A(1,a)+1;
else
A(1,a)=A(1,a)+1;
end
end
end
axes(handles.zhifangtu1)
set(handles.zhifangtu1,'Visible', 'off','Units', 'pixels','XLim',[1 256]);
x=1:1:256;
y=A(1,x)/(r*c);
stem(x,y,'.');
hold off;
%直方图均衡化程序
g=zeros(r,c);
d=255;
result=0;
x=zeros(1,256);
%计算统计概率x(k)
for k1=1:256
result=result+y(k1);
x(k1)=result;
end
%统计概率取整
x=round(d*x);
for i1=1:r
for j1=1:c
g(i1,j1)=x(picture(i1,j1)+1);
end
end
G=uint8(g);
axes(handles.junheng1)
set(handles.junheng1,'Visible', 'off','Units', 'pixels','XLim',[0 r],'yLim',[0 c]);
imshow(G);
hold on;
% --- Executes on button press in open_file2.
function open_file2_Callback(hObject, eventdata, handles)
% hObject handle to open_file2 (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);
[r,c]=size(picture);
axes(handles.huiduxianshi2)
set(handles.huiduxianshi2, 'Visible', 'off', 'Units', 'pixels' ,'XLim',[0 r],'yLim',[0 c]);
imshow(picture);
hold on;
%直方图显示程序
%picture1=picture+1;
A=zeros(1,256);
for i=1:r
for j=1:c
a=picture(i,j);
if(a>257)
a=256;
A(1,a)=A(1,a)+1;
elseif(a==0)
a=1;
A(1,a)=A(1,a)+1;
else
A(1,a)=A(1,a)+1;
end
end
end
axes(handles.zhifangtu2)
set(handles.zhifangtu2,'Visible', 'off','Units', 'pixels','XLim',[1 256]);
x=1:1:256;
y=A(1,x)/(r*c);
stem(x,y,'.');
hold off;
%直方图均衡化程序
g=zeros(r,c);
d=255;
result=0;
x=zeros(1,256);
%计算统计概率x(k)
for k1=1:256
result=result+y(k1);
x(k1)=result;
end
%统计概率取整
x=round(d*x);
for i1=1:r
for j1=1:c
g(i1,j1)=x(picture(i1,j1)+1);
end
end
G=uint8(g);
axes(handles.junheng2)
set(handles.junheng2,'Visible', 'off','Units', 'pixels','XLim',[0 r],'yLim',[0 c]);
imshow(G);
hold on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -