function varargout = test(varargin)
% TEST MATLAB code for test.fig
% TEST, by itself, creates a new TEST or raises the existing
% singleton*.
%
% H = TEST returns the handle to a new TEST or the handle to
% the existing singleton*.
%
% TEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEST.M with the given input arguments.
%
% TEST('Property','Value',...) creates a new TEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test_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 test
% Last Modified by GUIDE v2.5 22-Dec-2016 19:43:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test_OpeningFcn, ...
'gui_OutputFcn', @test_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 test is made visible.
function test_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 test (see VARARGIN)
% Choose default command line output for test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes test wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test_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 selectbutton.
function selectbutton_Callback(hObject, eventdata, handles)
% hObject handle to selectbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im %定义一个全局变量im
global tempim
[filename,pathname]=...
uigetfile({'*.*';'*.bmp';'*.tif';'*.png'},'select picture'); %选择图片路径
str=[pathname filename]; %合成路径+文件名
im=imread(str); %读取图片
[~,~,d3] = size(im);
if(d3 ~= 1)
I = rgb2gray(im);%如果是灰度图就不用先变换
I = double(I) / 255;
im = uint8(255 * I * 0.5 + 0.5);
end
tempim = im;
axes(handles.imaxe); %使用第一个axes
imshow(im); %显示图片
% --- Executes on button press in savebutton.
function savebutton_Callback(hObject, eventdata, handles)
% hObject handle to savebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global BW %定义处理后的图片BW这个全局变量
[filename,pathname,filterindex]=...
uiputfile({'*.bmp';'*.tif';'*.png'},'save picture'); %存储图片路径
if filterindex==0
return %如果取消操作,返回
else
str=[pathname filename]; %合成路径+文件名
axes(handles.bwaxe); %使用第二个axes
imwrite(BW,str); %写入图片信息,即保存图片
end
% --- Executes on selection change in intensityTransMenu.
function intensityTransMenu_Callback(hObject, eventdata, handles)
% hObject handle to intensityTransMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns intensityTransMenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from intensityTransMenu
% --- Executes during object creation, after setting all properties.
function intensityTransMenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to intensityTransMenu (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
% --- Executes on button press in IntensityTransBut.
function IntensityTransBut_Callback(hObject, eventdata, handles)
% hObject handle to IntensityTransBut (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
global BW;
v = get(handles.intensityTransMenu,'Value');
switch v
case 1 % 图像反转
J = double(im);
J = -J + (256 - 1);
BW = uint8(J);
case 2 % 对数变换
BW = im2uint8(mat2gray(log(1 + double(im))));
case 3 % 对比度拉伸变换
m = 256/2;
E = eval(get(handles.editE, 'String'));
BW = 1./(1 + (m./(double(im) + eps)).^E);
case 4 %直方图均衡
BW = histeq(im, 256);
case 5 %Sobel锐化
w = fspecial('sobel');
BW = filter2(w, im);
case 6 %Laplacian锐化
w = fspecial('laplacian');
BW = filter2(w, im);
end
axes(handles.bwaxe); %使用第二个axes
imshow(BW)
function editE_Callback(hObject, eventdata, handles)
% hObject handle to editE (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 editE as text
% str2double(get(hObject,'String')) returns contents of editE as a double
% --- Executes during object creation, after setting all properties.
function editE_CreateFcn(hObject, eventdata, handles)
% hObject handle to editE (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 showhistim.
function showhistim_Callback(hObject, eventdata, handles)
% hObject handle to showhistim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
figure
h1=imhist(im,16);
horz=1:16;
bar(horz,h1,0.8)
set(gca,'xtick',0:1:16);
% --- Executes on button press in showhistBW.
function showhistBW_Callback(hObject, eventdata, handles)
% hObject handle to showhistBW (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global BW;
figure
h1=imhist(BW,16);
horz=1:16;
评论0