function varargout = tuxiangGUI(varargin)
% TUXIANGGUI MATLAB code for tuxiangGUI.fig
% TUXIANGGUI, by itself, creates a new TUXIANGGUI or raises the existing
% singleton*.
%
% H = TUXIANGGUI returns the handle to a new TUXIANGGUI or the handle to
% the existing singleton*.
%
% TUXIANGGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TUXIANGGUI.M with the given input arguments.
%
% TUXIANGGUI('Property','Value',...) creates a new TUXIANGGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before tuxiangGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to tuxiangGUI_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
% Edit the above text to modify the response to help tuxiangGUI
% Last Modified by GUIDE v2.5 24-Dec-2023 16:35:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tuxiangGUI_OpeningFcn, ...
'gui_OutputFcn', @tuxiangGUI_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 tuxiangGUI is made visible.
function tuxiangGUI_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 tuxiangGUI (see VARARGIN)
% Choose default command line output for tuxiangGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes tuxiangGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tuxiangGUI_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 读图
[filename,pathname,filterindex]... %uigetfile用于打开一个检索文件的对话框,一般有三个参数,第一个参数为
=uigetfile({'*.*';'*.jpg';'*.tif';'*.png'},'选择图片'); %第三个参数的该对话框的默认打开路径,返回值为用户选择的文件路径和名称
if(filterindex==0)%filterindex为选择与否的结果,选择则为1,反之为0
return
else
str=[pathname filename]; %合成路径+文件名
im=imread(str); %读取图片
axes(handles.axes1); %使用axes7轴对象(创建一个轴图形对象)
imshow(im);
handles.I=im;%将原图像im当做handles句柄中的一个对象
guidata(hObject,handles);%保存当前窗口中的所有句柄
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function huiduchuli_Callback(hObject, eventdata, handles)
% hObject handle to huiduchuli (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function junhenghua_Callback(hObject, eventdata, handles)
% hObject handle to junhenghua (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.I;
Image = rgb2gray(I);
I2=histeq(Image);
axes(handles.axes1);imshow(Image);
axes(handles.axes2);imshow(I2);
% --------------------------------------------------------------------
function pipei_Callback(hObject, eventdata, handles)
% hObject handle to pipei (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
im = handles.I;
im = rgb2gray(im);
imRef = imread('303.png');
imRef =rgb2gray(imRef);
hist = imhist(im); % Compute histograms
histRef = imhist(imRef);
cdf = cumsum(hist) / numel(im); % Compute CDFs
cdfRef = cumsum(histRef) / numel(imRef);
% Compute the mapping
M = zeros(1,256);
for idx = 1 : 256
[tmp,ind] = min(abs(cdf(idx) - cdfRef));
M(idx) = ind-1;
end
imMatch = M(double(im)+1);
axes(handles.axes1);imshow(im,[]);title('原始图像');
axes(handles.axes2);imshow(imMatch,[]);title('直方图匹配后图像');
% --------------------------------------------------------------------
function huiduzhifangtu_Callback(hObject, eventdata, handles)
% hObject handle to huiduzhifangtu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.I;
Image = rgb2gray(I);
axes(handles.axes1);imshow(Image);
axes(handles.axes2);imhist(Image);
% --------------------------------------------------------------------
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 duishu_Callback(hObject, eventdata, handles)
% hObject handle to duishu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.I;
Igray=rgb2gray(I);
prompt={'a:' 'b:'};
name='Input for ContrastStretching';
numlines=1;
defaultanswer={'1' '20'};
anss=inputdlg(prompt,name,numlines,defaultanswer);
a=str2num(anss{1});
b=str2num(anss{2});
outputImage = a * log(1 + b * double(Igray));
axes(handles.axes1);imshow(Igray);
axes(handles.axes2);imshow(outputImage,[]);
% --------------------------------------------------------------------
function zhishu_Callback(hObject, eventdata, handles)
% hObject handle to zhishu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.I;
Igray=rgb2gray(I);
prompt={'a:'};
name='Input for ContrastStretching';
numlines=1;
defaultanswer={'1.5'};
anss=inputdlg(prompt,name,numlines,defaultanswer);
a=str2num(anss{1});
outputImage = uint8(255 * (double(Igray) / 255).^a);
axes(handles.axes1);imshow(Igray);
axes(handles.axes2);imshow(outputImage,[]);
% --------------------------------------------------------------------
function xianxing_Callback(hObject, eventdata, handles)
% hObject handle to xianxing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.I;
Igray=rgb2gray(I);
prompt={'a:' 'b:'};
name='Input for ContrastStretching';
numlines=1;
defaultanswer={'1' '-30'};
anss=inputdlg(prompt,name,numlines,defaultanswer);
a=str2num(anss{1})