实验目的
- 掌握matlab的可视化界面设计GUI
- 掌握图像的集合变换
实验内容
- 灰度图像的灰度线性映射,通过先行参数的调节(参数由文本框输入),实现图像质量调整,g(x,y)=a*f(x,y)+b
设计思路
1.加载灰度图像:首先需要将要处理的灰度图像加载到程序中
2.灰度转换:将彩色图像转换为灰度图像,以便后续进行灰度映射处理。
3.灰度线性映射:根据公式g(x,y)=a*f(x,y)+b,对灰度图像进行灰度线性映射处理。其中,a和b是由文本框输入的参数,f(x,y)表示原始灰度图像在(x,y)位置处的像素值,g(x,y)表示处理后的灰度图像在(x,y)位置处的像素值。
4.显示处理结果:将处理后的灰度图像显示出来
代码及注释
function pushbutton1_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;*.tif'},'选择一个图片','F:\test'); %获取图片地址
str=[pathname filename]; %存储文件地址
if isequal(filename,0)||isequal(pathname,0) %少部分即提示
warndlg('Please select a picture first!','Warning');
return;
else
handles.OriginalPic= imread(str); %读取原始图片
axes(handles.axes1); %在axes1中显示
imshow(handles.OriginalPic);
end;
guidata(hObject,handles);
function pushbutton2_Callback(hObject, eventdata, handles)
% 获取 GUI 界面中对应的 edit 控件中的数值
% 获取 axes1 中的图像
img=handles.OriginalPic
a = str2double(get(handles.edit2, 'String'));
b = str2double(get(handles.edit3, 'String'));
outputImg = a * double(img) + b;
axes(handles.axes2);
imshow(uint8(outputImg));
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
结果分析
在调整图像质量方面,可以通过调整斜率和截距来改变图像的亮度、对比度和明暗程度等特征。例如,如果想要增加图像的亮度,则需要适当增加斜率,同时减小截距;如果想要提高图像的对比度,则需要增加斜率,但不必改变截距。
- 实现图像的直方图显示,直方图均衡化(按钮)
设计思路
1.加载图像:使用imread函数或者其他相关函数从文件中加载图像。
2.显示原始图像:使用imshow函数将读取的图像显示在GUI界面上,以便用户进行操作。
3.显示直方图:计算图像的灰度直方图,并使用histogram函数将其绘制出来。histogram函数可以实现对图像直方图的自动计算并以柱状图的形式显示在GUI界面中。
4.实现直方图均衡化:根据用户的操作,在按钮的点击事件中调用histeq函数实现直方图均衡化,并更新GUI界面中的图像和直方图显示。
5.添加按钮:在GUI界面上添加按钮,并绑定事件响应函数,实现用户交互。
代码及注释
function pushbutton3_Callback(hObject, eventdata, handles)
img=handles.OriginalPic;
[counts, bins] = imhist(rgb2gray(img));
% 在 axes4 中绘制直方图
plot(handles.axes3, bins, counts);
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
img=handles.OriginalPic;
% 对图像进行直方图均衡化
img_eq = histeq(rgb2gray(img));
% 在 axes3 中显示均衡化后的图像
imshow(img_eq, 'Parent', handles.axes3);
% 计算均衡化后的图像的直方图
[counts_eq, bins_eq] = imhist(img_eq);
% 在 axes4 中绘制均衡化后的直方图
plot(handles.axes4, bins_eq, counts_eq);
结果分析
1.直方图显示:通过histogram函数生成灰度图像的直方图,可以清晰地看到不同灰度级出现的频率。可以通过直方图的形态来判断图像的亮度、对比度和色彩分布情况,为后续处理提供基础信息。
2.直方图均衡化:通过调用histeq函数实现直方图均衡化,可以增强图像的视觉效果。直方图均衡化会扩展图像的动态范围,并增加低灰度值像素的亮度,降低高灰度值像素的亮度,从而使图像整体更加明亮,具有更好的视觉效果。
3.读取两幅图像,实现基本代数运算
设计思路
1.在GUI中添加两个axes用于显示处理后的图像结果。
2.创建一个按钮或其他对象,用于触发加法和减法操作。
3.编写Matlab代码实现图像加法和减法。可以使用imread函数读取图像,imadd函数实现加法,imsubtract函数实现减法。
4.将处理后的结果显示在axes中。可以使用imshow函数将图像显示在axes中。
代码及注释
function pushbutton7_Callback(hObject, eventdata, handles)
res=imadd(handles.picture1,handles.picture2)
imshow(res, 'Parent', handles.axes10)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
res=imsubtract(handles.picture1,handles.picture2)
imshow(res, 'Parent', handles.axes11)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
结果分析
实现了读取两幅图像,并在Matlab中进行加法和减法的操作。
4.实现均值滤波和中值滤波(模板尺寸参数由文本框输入)
设计思路
均值滤波的实现思路如下:
- 获取待处理图像和滤波模板尺寸。
- 遍历待处理图像,对于每个像素,在滤波模板区域内取所有像素的平均值,将该平均值赋给当前像素。
- 重复步骤2,直到遍历整张图像。
中值滤波的实现思路如下:
- 获取待处理图像和滤波模板尺寸。
- 遍历待处理图像,对于每个像素,在滤波模板区域内取所有像素的灰度值,排序后取中间值,将该中间值赋给当前像素。
- 重复步骤2,直到遍历整张图像。
代码及注释
function pushbutton5_Callback(hObject, eventdata, handles)
originalImage =handles.OriginalPic;
originalImage=rgb2gray(originalImage);
filterSize = str2double(get(handles.edit4, 'String'));
% 应用均值滤波
meanFiltered = imfilter(originalImage, fspecial('average', [filterSize filterSize]));
% 在 axes3 和 axes4 中显示滤波后的图像
axes(handles.axes5);
imshow(meanFiltered);
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
originalImage =handles.OriginalPic;
originalImage=rgb2gray(originalImage);
% 从 edit box 中获取滤波器大小
filterSize = str2double(get(handles.edit4, 'String'));
% 应用中值滤波
medianFiltered = medfilt2(originalImage, [filterSize filterSize]);
axes(handles.axes6);
imshow(medianFiltered);
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
结果分析
1.均值滤波结果分析:均值滤波可以有效地平滑图像,但是会造成图像的细节部分模糊化。随着滤波模板尺寸的增大,可以更好地平滑图像,但是也会使得图像变得更加模糊。因此,在选择滤波模板尺寸时,需要根据具体情况进行调整。
2.中值滤波结果分析:中值滤波可以有效地去除椒盐噪声等高斯噪声之外的噪声,同时保留图像的边缘信息。同样地,随着滤波模板尺寸的增大,可以更好地去除噪声,但是也会使得图像的细节部分失真。因此,在选择滤波模板尺寸时,也需要进行适当的调整。
问题及解决方案
- 灰度图像的灰度线性映射,通过先行参数的调节(参数由文本框输入),实现图像质量调整,g(x,y)=a*f(x,y)+b
可能出现的问题:
- 输入的参数格式不正确或超出了合理范围,导致代码出错;
- 显示的结果不符合预期,可能是代码实现中存在逻辑错误。
解决方案:
- 在代码开发过程中,要对输入参数的格式、取值范围等进行严格控制和检查,可以使用Matlab自带的输入验证函数来实现;
- 调试代码时,可以逐步打印和检查中间结果,找到代码中的错误。
- 实现图像的直方图显示,直方图均衡化(按钮)
可能出现的问题:
- 图像读取失败或读取到的图像格式不支持直方图操作;
- 直方图计算错误或直方图均衡化算法效果不符合预期。
解决方案:
- 在代码开发过程中,要确保读取到的图像格式正确并支持直方图操作;
- 调试代码时,可以逐步打印和检查中间结果,找到代码中的错误;同时,也需要仔细设计并测试算法的效果,确保输出结果符合用户的预期
- 读取两幅图像,实现基本代数运算,实现均值滤波和中值滤波(模板尺寸参数由文本框输入)
可能出现的问题:
- 输入的参数格式不正确或超出了合理范围,导致代码出错;
- 图像读取失败或读取到的图像格式不支持所需的操作;
- 算法实现中存在逻辑错误,导致输出结果不符合预期。
解决方案:
- 在代码开发过程中,要对输入参数的格式、取值范围等进行严格控制和检查,可以使用Matlab自带的输入验证函数来实现;
- 调试代码时,可以逐步打印和检查中间结果,找到代码中的错误;同时,也需要仔细设计并测试算法的效果,确保输出结果符合用户的预期。
总结与心得
灰度线性映射是一种简单有效的图像增强方法,在实际应用中经常被使用。在代码实现时,需要注意对输入参数进行严格检查和控制,避免出现意外错误;同时,也需要仔细设计并测试算法的效果,确保输出结果符合用户的预期。直方图是一种常用的图像统计工具,能够有效地描述图像的分布情况。直方图均衡化算法能够增强图像的对比度,并使图像视觉效果更加饱满。在实际应用中,需要根据不同的场景和需求选择合适的算法,并对算法的实现进行充分的测试和调试。基本代数运算、均值滤波和中值滤波是图像处理中常用的操作,在实际应用中非常有用。在代码实现时,需要注意对输入参数进行严格检查和控制,避免出现意外错误;同时,也需要仔细设计并测试算法的效果,确保输出结果符合用户的预期。实现均值滤波和中值滤波是数字图像处理中的基本操作,掌握这两种滤波算法可以有效地去除图像噪声和平滑图像。在实现过程中,需要注意异常处理和边界问题,并且根据图像特点选择合适的模板尺寸以达到最佳效果。
附录
function varargout = text1(varargin)
% TEXT1 MATLAB code for text1.fig
% TEXT1, by itself, creates a new TEXT1 or raises the existing
% singleton*.
%
% H = TEXT1 returns the handle to a new TEXT1 or the handle to
% the existing singleton*.
%
% TEXT1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEXT1.M with the given input arguments.
%
% TEXT1('Property','Value',...) creates a new TEXT1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before text1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to text1_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 text1
% Last Modified by GUIDE v2.5 27-May-2023 14:40:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @text1_OpeningFcn, ...
'gui_OutputFcn', @text1_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 text1 is made visible.
function text1_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 text1 (see VARARGIN)
% Choose default command line output for text1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes text1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = text1_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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 pushbutton1.
function pushbutton1_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;*.tif'},'选择一个图片','F:\test'); %获取图片地址
str=[pathname filename]; %存储文件地址
if isequal(filename,0)||isequal(pathname,0) %少部分即提示
warndlg('Please select a picture first!','Warning');
return;
else
handles.OriginalPic= imread(str); %读取原始图片
axes(handles.axes1); %在axes1中显示
imshow(handles.OriginalPic);
end;
guidata(hObject,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)
% --- 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
% --- 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
% --- 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
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 获取 GUI 界面中对应的 edit 控件中的数值
% 获取 axes1 中的图像
img=handles.OriginalPic
a = str2double(get(handles.edit2, 'String'));
b = str2double(get(handles.edit3, 'String'));
outputImg = a * double(img) + b;
axes(handles.axes2);
imshow(uint8(outputImg));
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
img=handles.OriginalPic;
[counts, bins] = imhist(rgb2gray(img));
% 在 axes4 中绘制直方图
plot(handles.axes3, bins, counts);
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
img=handles.OriginalPic;
% 对图像进行直方图均衡化
img_eq = histeq(rgb2gray(img));
% 在 axes3 中显示均衡化后的图像
imshow(img_eq, 'Parent', handles.axes3);
% 计算均衡化后的图像的直方图
[counts_eq, bins_eq] = imhist(img_eq);
% 在 axes4 中绘制均衡化后的直方图
plot(handles.axes4, bins_eq, counts_eq);
% --- 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( gca, 'xtick', [] ); %去掉x轴的刻度
set( gca, 'ytick', [] ); %去掉y轴的刻度
% 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( gca, 'xtick', [] ); %去掉x轴的刻度
set( gca, 'ytick', [] ); %去掉y轴的刻度
% Hint: place code in OpeningFcn to populate axes2
% --- Executes during object creation, after setting all properties.
function axes3_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set( gca, 'xtick', [] ); %去掉x轴的刻度
set( gca, 'ytick', [] ); %去掉y轴的刻度
% Hint: place code in OpeningFcn to populate axes3
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
originalImage =handles.OriginalPic;
originalImage=rgb2gray(originalImage);
filterSize = str2double(get(handles.edit4, 'String'));
% 应用均值滤波
meanFiltered = imfilter(originalImage, fspecial('average', [filterSize filterSize]));
% 在 axes3 和 axes4 中显示滤波后的图像
axes(handles.axes5);
imshow(meanFiltered);
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
originalImage =handles.OriginalPic;
originalImage=rgb2gray(originalImage);
% 从 edit box 中获取滤波器大小
filterSize = str2double(get(handles.edit4, 'String'));
% 应用中值滤波
medianFiltered = medfilt2(originalImage, [filterSize filterSize]);
axes(handles.axes6);
imshow(medianFiltered);
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 during object creation, after setting all properties.
function axes6_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set( gca, 'xtick', [] ); %去掉x轴的刻度
set( gca, 'ytick', [] ); %去掉y轴的刻度
% Hint: place code in OpeningFcn to populate axes6
% --- Executes during object creation, after setting all properties.
function axes5_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes5 (see GCBO)
set( gca, 'xtick', [] ); %去掉x轴的刻度
set( gca, 'ytick', [] ); %去掉y轴的刻度
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes5
% --- Executes during object creation, after setting all properties.
function axes4_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes4 (see GCBO)
set( gca, 'xtick', [] ); %去掉x轴的刻度
set( gca, 'ytick', [] ); %去掉y轴的刻度
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes4
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
res=imadd(handles.picture1,handles.picture2)
imshow(res, 'Parent', handles.axes10)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
res=imsubtract(handles.picture1,handles.picture2)
imshow(res, 'Parent', handles.axes11)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif'},'选择一个图片','F:\test'); %获取图片地址
str=[pathname filename]; %存储文件地址
if isequal(filename,0)||isequal(pathname,0) %少部分即提示
warndlg('Please select a picture first!','Warning');
return;
else
handles.picture1= imread(str); %读取原始图片
axes(handles.axes8); %在axes1中显示
imshow(handles.picture1);
end;
guidata(hObject,handles);
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif'},'选择一个图片','F:\test'); %获取图片地址
str=[pathname filename]; %存储文件地址
if isequal(filename,0)||isequal(pathname,0) %少部分即提示
warndlg('Please select a picture first!','Warning');
return;
else
handles.picture2= imread(str); %读取原始图片
axes(handles.axes9); %在axes1中显示
imshow(handles.picture2);
end;
guidata(hObject,handles);
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)