Matlab具有强大的函数运算功能,利用这一点可以进行像素级的计算,也就是图像处理。这款软件基于Matlab平台,用户可以在软件界面中打开需要修改的图片,选择想要变换的效果,通过拖动滑动条可以动态显示修改后的图片效果。
涉及到的图像处理包括以下三种灰度变换:
二值化
伽马变换
对数变换
不允许修改空图片,必须打开一张图片后才能获得修改图片的权限。
打开文件后,面板上显示两张图片,左边的是原图,右边的是原图副本,可以动态显示修改效果。如图:
其中PhotoProcess包含三个菜单项,分别是
下面分别对这三种功能进行演示:
其中在子窗口中出现的拖动条可以动态调整二值化阀值(Threshold),这里取值0到1,从而显示出不一样的效果。
类似二值化功能,这里也有一个拖动条,可以动态调整γ值,我们知道伽马变换的表达式:
对数变换公式:
退出的时候如果还未保存将提示是否需要保存。 可选格式为bmp和jpg格式。如图为修改后的图片
[数字图像处理]灰度变换——反转,对数变换,伽马变换,灰度拉伸,灰度切割,位图切割
《一个实例搞定matlab界面编程》 https://wenku.baidu.com/view/fdf6ad6925c52cc58bd6be8e.html
DIP.m
function varargout = DIP(varargin)
% DIP MATLAB code for DIP.fig
% DIP, by itself, creates a new DIP or raises the existing
% singleton*.
%
% H = DIP returns the handle to a new DIP or the handle to
% the existing singleton*.
%
% DIP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DIP.M with the given input arguments.
%
% DIP('Property','Value',...) creates a new DIP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DIP_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DIP_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 DIP
% Last Modified by GUIDE v2.5 10-Apr-2017 16:55:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DIP_OpeningFcn, ...
'gui_OutputFcn', @DIP_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 DIP is made visible.
function DIP_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 DIP (see VARARGIN)
% Choose default command line output for DIP
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DIP wait for user response (see UIRESUME)
% uiwait(handles.figure_DIP);
setappdata(handles.figure_DIP,'img_src',0);
set(handles.photoprocess,'Enable','off');
setappdata(handles.figure_DIP,'bSave',false);
setappdata(handles.figure_DIP,'bChanged',false);
setappdata(handles.figure_DIP,'fstSave',true);
setappdata(handles.figure_DIP,'fstPath',0);
set(handles.toolSave,'Enable','off');
set(handles.save,'Enable','off');
set(handles.axes1,'visible','off');
set(handles.axes2,'visible','off');
% --- Outputs from this function are returned to the command line.
function varargout = DIP_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 file_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function photoprocess_Callback(hObject, eventdata, handles)
% hObject handle to photoprocess (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_8_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
% hObject handle to help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function toBinary_Callback(hObject, eventdata, handles)
% hObject handle to toBinary (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%axes(handles.axes2);
%img_src = getappdata(handles.figure_DIP,'img_src');
%imshow(img_src);
h = toBW;
setappdata(handles.figure_DIP,'bChanged',true);
set(handles.toolSave,'Enable','on');
set(handles.save,'Enable','on');
set(handles.axes2,'visible','on');
% --------------------------------------------------------------------
function gammatrans_Callback(hObject, eventdata, handles)
% hObject handle to gammatrans (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = toGamma;
setappdata(handles.figure_DIP,'bChanged',true);
set(handles.toolSave,'Enable','on');
set(handles.save,'Enable','on');
set(handles.axes2,'visible','on');
% --------------------------------------------------------------------
function contrast_Callback(~, eventdata, handles)
% hObject handle to contrast (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function brightness_Callback(hObject, eventdata, handles)
% hObject handle to brightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.bmp;*.jpg;*.png;*.jpeg', 'Image Files (*.bmp, *.jpg, *.png,*.jpeg)'; '*.*', 'All Files (*.*)'}, 'Pick an image');
if isequal(filename,0) || isequal(pathname,0),
return;
end
axes(handles.axes1);%用axes命令设定当前操作的坐标轴是axes1
fpath=[pathname filename];%将文件名和目录名组合成一个完整的路径
img_src = imread(fpath);
imshow(img_src);
axes(handles.axes2);
imshow(img_src);
setappdata(handles.figure_DIP,'img_src',img_src);
set(handles.photoprocess,'Enable','on');
set(handles.axes1,'visible','on');
% --------------------------------------------------------------------
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)
fstSave=getappdata(handles.figure_DIP,'fstSave');
if(fstSave==true)
[filename, pathname] = uiputfile({'*.bmp','BMP files';'*.jpg;','JPG files'}, 'Pick an Image');
if isequal(filename,0) || isequal(pathname,0)
return;%如果点了“取消”
else
fpath=fullfile(pathname, filename);%获得全路径的另一种方法
end
img_dst=getimage(handles.axes2);
imwrite(img_dst,fpath);%保存图片
setappdata(handles.figure_DIP,'fstPath',fpath);
setappdata(handles.figure_DIP,'bSave',true);
setappdata(handles.figure_DIP,'fstSave',false);
else
img_dst=getimage(handles.axes2);
fpath=getappdata(handles.figure_DIP,'fstPath');
imwrite(img_dst,fpath);
end
% --------------------------------------------------------------------
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
bChanged=getappdata(handles.figure_DIP,'bChanged');%获得是否更改
bSave=getappdata(handles.figure_DIP,'bSave');%获得是否保存
if bChanged==true && bSave==false,%更改了,而没保存时
btnName=questdlg('Not Saved Yet','Warning','save','leave','save');%用提问对话框
switch btnName,
case 'save', %执行axes_dst_menu_save_Callback的功能
feval(@save_Callback,handles.save,eventdata,handles);
case 'leave',%什么也不做
end
end
h=findobj('Tag','figure_toBW');%查找是否打开设置图像二值化参数窗口
hh=findobj('Tag','figure_toLogTrans');
hhh=findobj('Tag','figure_toGamma');
if ~isempty(h),%找到的话,则关闭
close(h);
close(hh);
close(hhh);
end
close(findobj('Tag','figure_DIP'));%关闭主窗口
% --------------------------------------------------------------------
function toolOpen_ClickedCallback(hObject, eventdata, handles)
% hObject handle to toolOpen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
feval(@open_Callback,handles.open,eventdata,handles);
% --------------------------------------------------------------------
function toolSave_ClickedCallback(hObject, eventdata, handles)
% hObject handle to toolSave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
feval(@save_Callback,handles.save,eventdata,handles);
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject,'xTick',[]);
set(hObject,'ytick',[]);
set(hObject,'box','on');
% Hint: place code in OpeningFcn to populate axes1
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject,'xTick',[]);
set(hObject,'ytick',[]);
set(hObject,'box','on');
% Hint: place code in OpeningFcn to populate axes2
% --------------------------------------------------------------------
function logtrans_Callback(hObject, eventdata, handles)
% hObject handle to logtrans (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%axes(handles.axes2);
%img_src = getappdata(handles.figure_DIP,'img_src');
%imshow(img_src);
h = toLogTrans;
setappdata(handles.figure_DIP,'bChanged',true);
set(handles.toolSave,'Enable','on');
set(handles.save,'Enable','on');
set(handles.axes2,'visible','on');
toBW.m
function varargout = toBW(varargin)
% TOBW MATLAB code for toBW.fig
% TOBW, by itself, creates a new TOBW or raises the existing
% singleton*.
%
% H = TOBW returns the handle to a new TOBW or the handle to
% the existing singleton*.
%
% TOBW('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TOBW.M with the given input arguments.
%
% TOBW('Property','Value',...) creates a new TOBW or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before toBW_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to toBW_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 toBW
% Last Modified by GUIDE v2.5 10-Apr-2017 00:49:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @toBW_OpeningFcn, ...
'gui_OutputFcn', @toBW_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 toBW is made visible.
function toBW_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 toBW (see VARARGIN)
% Choose default command line output for toBW
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%找到原始界面的句柄
HH = findobj('Tag','figure_DIP');
DIP = guihandles(HH);
setappdata(handles.figure_toBW,'DIP',DIP)
% UIWAIT makes toBW wait for user response (see UIRESUME)
% uiwait(handles.figure_toBW);
% --- Outputs from this function are returned to the command line.
function varargout = toBW_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 slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (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
val = get(hObject,'Value');
set(handles.text_bw,'String',num2str(val));
DIP = getappdata(handles.figure_toBW,'DIP');
axes(DIP.axes2);
img_src = getappdata(DIP.figure_DIP,'img_src');
bw = im2bw(img_src,val);
imshow(bw);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (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.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
LogTrans.m
function [g] = LogTrans(f,c,v)
%此处显示详细说明
h = mat2gray(f,[0,255]);
g = c*log2(1+v*h)/log2(v+1);
end
toLogTrans.m
function varargout = toLogTrans(varargin)
% TOLOGTRANS MATLAB code for toLogTrans.fig
% TOLOGTRANS, by itself, creates a new TOLOGTRANS or raises the existing
% singleton*.
%
% H = TOLOGTRANS returns the handle to a new TOLOGTRANS or the handle to
% the existing singleton*.
%
% TOLOGTRANS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TOLOGTRANS.M with the given input arguments.
%
% TOLOGTRANS('Property','Value',...) creates a new TOLOGTRANS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before toLogTrans_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to toLogTrans_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 toLogTrans
% Last Modified by GUIDE v2.5 10-Apr-2017 16:41:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @toLogTrans_OpeningFcn, ...
'gui_OutputFcn', @toLogTrans_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 toLogTrans is made visible.
function toLogTrans_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 toLogTrans (see VARARGIN)
% Choose default command line output for toLogTrans
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%找到原始界面的句柄
HH = findobj('Tag','figure_DIP');
DIP = guihandles(HH);
setappdata(handles.figure_toLogTrans,'DIP',DIP)
setappdata(handles.figure_toLogTrans,'val_C',0);
setappdata(handles.figure_toLogTrans,'val_V',0);
% UIWAIT makes toLogTrans wait for user response (see UIRESUME)
% uiwait(handles.figure_toLogTrans);
% --- Outputs from this function are returned to the command line.
function varargout = toLogTrans_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 slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (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
val_C = get(hObject,'Value');
set(handles.text2,'String',num2str(val_C));
setappdata(handles.figure_toLogTrans,'val_C',val_C);
val_V = getappdata(handles.figure_toLogTrans,'val_V');
DIP = getappdata(handles.figure_toLogTrans,'DIP');
axes(DIP.axes2);
img_src = getappdata(DIP.figure_DIP,'img_src');
bw = LogTrans(img_src,val_C,val_V);
imshow(bw);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (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.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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
val_V = get(hObject,'Value');
set(handles.text4,'String',num2str(val_V));
setappdata(handles.figure_toLogTrans,'val_V',val_V);
val_C = getappdata(handles.figure_toLogTrans,'val_C');
DIP = getappdata(handles.figure_toLogTrans,'DIP');
axes(DIP.axes2);
%img_src = getimage(DIP.axes2);
img_src = getappdata(DIP.figure_DIP,'img_src');
%bw = val_C*log2(1+val_V*img_src)/log2(val_V+1);
bw = LogTrans(img_src,val_C,val_V);
imshow(bw);
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (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.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
toGamma.m
function varargout = toGamma(varargin)
% TOGAMMA MATLAB code for toGamma.fig
% TOGAMMA, by itself, creates a new TOGAMMA or raises the existing
% singleton*.
%
% H = TOGAMMA returns the handle to a new TOGAMMA or the handle to
% the existing singleton*.
%
% TOGAMMA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TOGAMMA.M with the given input arguments.
%
% TOGAMMA('Property','Value',...) creates a new TOGAMMA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before toGamma_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to toGamma_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 toGamma
% Last Modified by GUIDE v2.5 10-Apr-2017 21:32:21
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @toGamma_OpeningFcn, ...
'gui_OutputFcn', @toGamma_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 toGamma is made visible.
function toGamma_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 toGamma (see VARARGIN)
% Choose default command line output for toGamma
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%找到原始界面的句柄
HH = findobj('Tag','figure_DIP');
DIP = guihandles(HH);
setappdata(handles.figure_toGamma,'DIP',DIP)
% UIWAIT makes toGamma wait for user response (see UIRESUME)
% uiwait(handles.figure_toGamma);
% --- Outputs from this function are returned to the command line.
function varargout = toGamma_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 slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = get(hObject,'Value');
set(handles.text2,'String',num2str(val));
DIP = getappdata(handles.figure_toGamma,'DIP');
axes(DIP.axes2);
img_src = getappdata(DIP.figure_DIP,'img_src');
c = 1;
bw = GammaTrans(img_src,c,val);
imshow(bw);
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (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.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
GammaTrans.m
function [g]=GammaTrans(f,c,gamma)
% 此处显示详细说明
h = mat2gray(f,[0,255]);
g = c*(h.^gamma);
end