通过GUI界面创建简易GUI软件,命令窗口输入guide,打开untitled.fig进入控件编辑界面,运行进入使用界面,以彩色图像RGBimageB.tiff为例,实现九种功能:图片的打开;转换为灰度图像;增加对比度;图片旋转(逆时针);增加高斯噪声;添加椒盐噪声;消除噪声;图像增强;边缘检测(可选五种边缘检测算子)。


代码(matlab)

function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled% Last Modified by GUIDE v2.5 10-Jun-2021 11:13:53% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @untitled_OpeningFcn, ...'gui_OutputFcn',  @untitled_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before untitled is made visible.
function untitled_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 untitled (see VARARGIN)% Choose default command line output for untitled
%初始化
handles.output = hObject;
handles.imgfilename = [];
handles.imgdata = [];
handles.imgoutput = [];% Update handles structure
guidata(hObject, handles);% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = untitled_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)
% 按钮一的运行代码(打开图片)
[imgfilename imgpathname]=uigetfile({'*.jpg;*.png;*.tiff;*.tif;*.bmp'},'Select a RGB image');
if imgfilenameimgdata=imread([imgpathname '\' imgfilename]);image(handles.axes1,imgdata);handles.imgfilename=imgfilename;handles.imgdata=imgdata;
end
guidata(hObject,handles)% --- Executes on button press in pushbutton2.
function pushbutton2_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)
% 按钮二的运行代码(转换为灰度图像)
if ~isempty(handles.imgfilename)imgoutput=rgb2gray(handles.imgdata);image(handles.axes2,imgoutput)colormap(handles.axes2,gray(256))%灰度图像要加背景才能显示正常handles.imgoutput=imgoutput;handles.imgdata=imgoutput;%新图片存为图片数据,可对新图片进行下一步操作
endguidata(hObject,handles)% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% 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)
% 按钮三的运行代码(使用伽马变换增加对比度函数)I = im2double(handles.imgdata);I = mat2gray(I); % 归一化imgoutput = imadjust(I,[0.2 0.8],[0.1 1]);image(handles.axes2,imgoutput)handles.imgoutput=imgoutput;handles.imgdata=imgoutput;
guidata(hObject,handles)% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%按钮四的运行代码(逆时针旋转)
imgoutput = imrotate(handles.imgdata,90,'crop');
image(handles.axes2,imgoutput)
handles.imgoutput=imgoutput;
handles.imgdata=imgoutput;
guidata(hObject,handles)% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% 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)
%按钮五的运行代码(添加高斯噪声)
imgoutput=imnoise(handles.imgdata,'gaussian',0,0.02);
image(handles.axes2,imgoutput)
handles.imgoutput=imgoutput;
handles.imgdata=imgoutput;
guidata(hObject,handles)% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% 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)
%按钮六的运行代码(添加椒盐噪声)
imgoutput=imnoise(handles.imgdata,'salt & pepper');
image(handles.axes2,imgoutput)
handles.imgoutput=imgoutput;
handles.imgdata=imgoutput;
guidata(hObject,handles)% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% 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)
%按钮七的运行代码(消除噪声)
[a,b,c]=ddencmp('den','wv',handles.imgdata);
imgoutput=wdencmp('gbl',handles.imgdata,'sym4',2,a,b,c);
imgoutput=uint8(imgoutput);
image(handles.axes2,imgoutput)
handles.imgoutput=imgoutput;
handles.imgdata=imgoutput;
guidata(hObject,handles)% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% 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)
%按钮八的运行代码(直方图均衡化实现图像增强)
imgoutput=histeq(handles.imgdata);
image(handles.axes2,imgoutput)
handles.imgoutput=imgoutput;
handles.imgdata=imgoutput;
guidata(hObject,handles)% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, 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)
%按钮九的运行代码(以sobel算子为例提取边缘)
I=rgb2gray(handles.imgdata);
imgoutput = edge(I,'sobel');
imagesc(handles.axes2,imgoutput);
%或者用image(handles.axes2,im2uint8(double(imgoutput)));语句,logical二值图像颜色范围太小,没法用image直接显示,
colormap(handles.axes2,gray(256));
handles.imgoutput=imgoutput;
guidata(hObject,handles)%以下单选框中五个选项可以选择边缘检测算子类型(点击即生成图片)
% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=rgb2gray(handles.imgdata);
imgoutput = edge(I,'sobel');
imagesc(handles.axes2,imgoutput)
colormap(handles.axes2,gray(256));
handles.imgoutput=imgoutput;
guidata(hObject,handles)
% Hint: get(hObject,'Value') returns toggle state of radiobutton3% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=rgb2gray(handles.imgdata);
imgoutput = edge(I,'prewitt');
imagesc(handles.axes2,imgoutput)
colormap(handles.axes2,gray(256));
handles.imgoutput=imgoutput;
guidata(hObject,handles)
% Hint: get(hObject,'Value') returns toggle state of radiobutton4% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=rgb2gray(handles.imgdata);
imgoutput = edge(I,'log');
imagesc(handles.axes2,imgoutput)
colormap(handles.axes2,gray(256));
handles.imgoutput=imgoutput;
guidata(hObject,handles)
% Hint: get(hObject,'Value') returns toggle state of radiobutton5% --- Executes on button press in radiobutton9.
function radiobutton9_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=rgb2gray(handles.imgdata);
imgoutput = edge(I,'canny');
imagesc(handles.axes2,imgoutput)
colormap(handles.axes2,gray(256));
handles.imgoutput=imgoutput;
guidata(hObject,handles)
% Hint: get(hObject,'Value') returns toggle state of radiobutton9% --- Executes on button press in radiobutton10.
function radiobutton10_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=rgb2gray(handles.imgdata);
imgoutput = edge(I,'roberts');
imagesc(handles.axes2,imgoutput)
colormap(handles.axes2,gray(256));
handles.imgoutput=imgoutput;
guidata(hObject,handles)
% Hint: get(hObject,'Value') returns toggle state of radiobutton10

GUI界面

运行示例




补充

实验中实现边缘检测功能时,发现使用image函数显示图像出现全蓝的现象,需要改用imagesc函数才能正常显示,或使用image(handles.axes2,im2uint8(double(imgoutput)))语句,原因是logical二值图像颜色范围太小,如果使用image将没法直接显示。

数字图像处理:matlab编写简易GUI软件相关推荐

  1. [数字图像处理Matlab]任选一幅灰度图,自行编写程序,完成直方图均衡化。鼠鼠的数字图像处理实验要求:不能用MATLAB自带的histeq函数实现直方图均衡化

    数学理论前提:见数字图像处理(第三版) 李俊山等编著  p50-53 1.利用imhist函数统计像素点个数 Im = imread("C:\Users\鼠鼠\Desktop\数字图像处理m ...

  2. 图像处理----入门资料,Matlab r2019最新版,r2008a,《数字图像处理》冈萨雷斯 第三版 《数字图像处理 Matlab 版》

    研究生想研究的方向是图像处理,现在离开学还有四个月,希望能稍微入门吧.同时也希望通过博客的形式记录一下学习的进度,学习的心情.目前学习两周,安装了基本的软件,收集书籍,学习了灰度变换,空间滤波,频率滤 ...

  3. 【资源分享】数字图像处理MATLAB版冈萨雷斯+中文高清版+随书源码链接

    写在这里的初衷,一是备忘,二是希望得到高人指点,三是希望能遇到志同道合的朋友. 目录 1.数字图像处理MATLAB版冈萨雷斯+中文高清版 2.数字图像处理MATLAB版冈萨雷斯随书源码 1.数字图像处 ...

  4. 【数字图像处理matlab】(HSI变换融合算法)

    [数字图像处理matlab](HSI变换融合算法) 输入一张高分辨率的全色影像HR,一张低分辨率的多光谱影像MS,采用HSI变换融合算法实现影像融合,其中RGB与HSI影像的相互转换调用自定义函数RG ...

  5. 《数字图像处理 MATLAB版》学习笔记

    学习教材:<数字图像处理 MATLAB版>(第二版) 冈萨雷斯 学习过程中的图片代码和及我收集的一些关于数字图像处理的其他学习资料,需要的可以评论留下邮箱(需要购买专栏),加油 文章目录 ...

  6. 数字图像处理MATLAB学习笔记(五)

    数字图像处理MATLAB学习笔记(五) Color Image Processing 1 Color Image Representation in MATLAB 这里不多说了,彩色图片在计算机中以R ...

  7. MATLAB 编写简易电子琴(二)

    前几天用MATLAB做了一个简易电子琴,链接: MATLAB 编写简易电子琴 这个电子琴输入用的input函数,每按一个字符要敲回车,现在用另一种方法解决了这个问题: 使用 set(gcf,'KeyP ...

  8. matlab电子琴,MATLAB 编写简易电子琴

    Bilbili视频:MATLAB 编写简易电子琴 声音模型 声音本质是机械振动产生的波通过介质传播至人耳,这一振动可由函数x ( t ) x(t)x(t)表示,离散化后即为向量x n x_nxn​以及 ...

  9. 数字图像处理matlab作业,数字图像处理matlab大作业

    <数字图像处理matlab大作业>由会员分享,可在线阅读,更多相关<数字图像处理matlab大作业(23页珍藏版)>请在人人文库网上搜索. 1.几个图像处理实例,matlab ...

最新文章

  1. vbscript input select 添加个option根据value值到指定位置--相当于排序
  2. 荐读 | 9篇近期社会化推荐论文
  3. python读取excel写入数据库_python实现读取excel写入mysql的小工具详解
  4. Spring MVC的框架组件
  5. Cocos2d-x 寻路算法解析(一): 距离优先
  6. 使用site-maven-plugin在github上搭建公有仓库
  7. 钉钉api 获取 accesstoken_python3自定义告警信息发送至钉钉群
  8. 箱式图 添加异常值平均值_什么是脏数据?怎样用箱形图分析异常值?终于有人讲明白了...
  9. 用习惯了windows系统要怎样去认识linux系统(一)
  10. oracle数据库的拼接字符串,Oracle数据库拼接字符串
  11. centos7常用工具安装手册
  12. 达摩院python教程视频_Python400集大型视频,无偿分享,从正确方向学习python,全套python入门完整视频...
  13. Keras:模型评估
  14. 概率假设密度滤波 matlab,概率假设密度滤波的物理空间意义
  15. 1218 正方形还是圆形
  16. css 大于号 标签_css选择器 ~ (波浪号)、+(加号)、(大于号)的用法解析和举例...
  17. iphone邮箱收件服务器设置,iphone中使用国内邮箱设置方法
  18. 知识图谱·概念与技术--第1章学习笔记--知识图谱概述--知识图谱的概念,与传统语义网络的区别
  19. 华为首款台式机计算机发布,华为首款商用台式机一文读懂:商用PC进入智慧时代...
  20. linux系统深度评测,真国产,深度linux系统评测第二集

热门文章

  1. Lazada店铺运营--提升销量的核心技巧及店铺前期运营规划
  2. 首发Yolov8涨点神器:华为诺亚2023极简的神经网络模型 VanillaNet---VanillaBlock助力检测,实现暴力涨点
  3. 数字藏品人人爱,视频平台竞折腰
  4. 豪情-关于生活工作学习之感悟-第三篇
  5. 隐藏Android11系统的鼠标
  6. 操作系统复习(十五)——缓冲区管理与磁盘调度算法
  7. 《火影忍者》157集鸣人天天宁次小李与雷牙的战斗及法制分析
  8. [细读经典]Megatron论文和代码详细分析(1)
  9. php使用referer,php如何设置伪造referer地址
  10. 会议音频处理器(8进8出)