在好例子网,分享、交流、成长!
您当前所在位置:首页MATLAB 开发实例MATLAB语言基础 → HSI图像处理及GUI设计

HSI图像处理及GUI设计

MATLAB语言基础

下载此实例
  • 开发语言:MATLAB
  • 实例大小:1.46M
  • 下载次数:5
  • 浏览次数:78
  • 发布时间:2020-08-11
  • 实例类别:MATLAB语言基础
  • 发 布 人:laterVS
  • 文件格式:.zip
  • 所需积分:5
 相关标签: 图像处理 GUI 设计 图像 UI

实例介绍

【实例简介】

MATLAB图像处理及GUI设计

图像滤波去噪

亮度调节

对比度调节

饱和度调节

HSI域的变化

【实例截图】

【核心代码】


function varargout = myHSI(varargin)
% MYHSI MATLAB code for myHSI.fig
%      MYHSI, by itself, creates a new MYHSI or raises the existing
%      singleton*.
%
%      H = MYHSI returns the handle to a new MYHSI or the handle to
%      the existing singleton*.
%
%      MYHSI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MYHSI.M with the given input arguments.
%
%      MYHSI('Property','Value',...) creates a new MYHSI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before myHSI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to myHSI_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 myHSI

% Last Modified by GUIDE v2.5 04-Aug-2020 13:01:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @myHSI_OpeningFcn, ...
                   'gui_OutputFcn',  @myHSI_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 myHSI is made visible.
function myHSI_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 myHSI (see VARARGIN)

% Choose default command line output for myHSI
handles.output = hObject;
axes(handles.axes1);
set(gca, 'vis', 'off')
axes(handles.axes2);
set(gca, 'vis', 'off')
axes(handles.axes3);
set(gca, 'vis', 'off')
axes(handles.axes4);
set(gca, 'vis', 'off')
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes myHSI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = myHSI_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 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)
filter = { ...
'*.bmp;*.jpg;*.gif;*.emf', '所有图像文件 (*.bmp; *.jpg; *.gif; *emf)'; ...
'*.bmp', '位图文件 (*.bmp)'; ...
'*.jpg', 'JPEG文件 (*.jpg)'; ...
'*.gif', 'GIF文件 (*.gif)'; ...
'*.emf', '图元文件 (*.emf)'; ...
'*.*', '所有文件 (*.*)' ...
};

% 选择文件
[filename, pathname] = uigetfile( filter, '打开...');
if isequal(filename,0) | isequal(pathname,0), return, end

% 读入图像并显示
[X, map] = imread([pathname filename]);
% colormap(map)
% image(X)
axes(handles.axes1); cla reset;
imshow(X);title('原图');
% 设置坐标系为适合显示图像的方式
% axis image
set(gca, 'vis', 'off')
handles.I=X;
guidata(hObject, handles);



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 pushbutton2_Callback(hObject, eventdata, handles)
% 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)
I=handles.I;
a=str2num(get(handles.edit1,'string'))
% 平滑滤波-高斯滤波
W = fspecial('gaussian',[a,a],1);
I = imfilter(I, W, 'replicate');
axes(handles.axes2); cla reset;
imshow(I);title('高斯滤波后图像');


% --- 祛斑操作
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=handles.I;
n =7;   % 窗口大小
[ height, width ] = size(I);
x1 = double(I);
x2 = x1;
for i = 1: height-n 1
    for j = 1:width-n 1
        mb = x1( i:(i n-1),  j:(j n-1) );%获取图像中n*n的矩阵
        mb = mb(:);                      %将mb变成向量化,变成一个列向量
        mm = median(mb);                 %取中间值
        x2( i (n-1)/2,  j (n-1)/2 ) = mm;
    end
end
I = uint8(x2);
axes(handles.axes2); cla reset;
imshow(I);title('中值滤波后(去斑)');


% --- 亮度调节
function slider3_Callback(hObject, eventdata, handles)
% hObject    handle to slider3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 0.02的步长
I=handles.I;
% -1:0.2:1 -->   0.1:10
v=get(handles.slider3,'value');
if v<0
    m=1 v
end
if v>=0
    m=v*10
end
    
axes(handles.axes2); cla reset;
I=rgb2hsi(I);
% figure;                                                                                                                                                                                                              
% imshow(I);title('HSI域');
H1=I(:,:,1);
S1=I(:,:,2);
X1=I(:,:,3)*m; % 亮度调节
% 色度 饱和度 强度
I=cat(3,H1,S1,X1);
f1=hsi2rgb(I);
imshow(f1),title('HSI亮度调节');
% set(handles.text2,'string',num2str(ceil(100*v)));
% 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 slider3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider3 (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


% --- 饱和度调节
function slider4_Callback(hObject, eventdata, handles)
% hObject    handle to slider4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 0.02的步长
I=handles.I;
% -1:0.2:1 -->   0.1:10
v=get(handles.slider4,'value');
if v<0
    m=1 v
end
if v>=0
    m=v*10
end
    
axes(handles.axes2); cla reset;
I=rgb2hsi(I);
% figure;                                                                                                                                                                                                              
% imshow(I);title('HSI域');
H1=I(:,:,1);
S1=I(:,:,2)*m;
X1=I(:,:,3); % 亮度调节
% 色度 饱和度 强度
I=cat(3,H1,S1,X1);
f1=hsi2rgb(I);
imshow(f1),title('HSI饱和度调节');
% 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 slider4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider4 (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


% ---打开图像
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)
filter = { ...
'*.bmp;*.jpg;*.gif;*.emf', '所有图像文件 (*.bmp; *.jpg; *.gif; *emf)'; ...
'*.bmp', '位图文件 (*.bmp)'; ...
'*.jpg', 'JPEG文件 (*.jpg)'; ...
'*.gif', 'GIF文件 (*.gif)'; ...
'*.emf', '图元文件 (*.emf)'; ...
'*.*', '所有文件 (*.*)' ...
};

% 选择文件
[filename, pathname] = uigetfile( filter, '打开...');
if isequal(filename,0) | isequal(pathname,0), return, end

% 读入图像并显示
[X, map] = imread([pathname filename]);
% colormap(map)
% image(X)
axes(handles.axes3); cla reset;
imshow(X);title('原图');
% 设置坐标系为适合显示图像的方式
% axis image
set(gca, 'vis', 'off')
handles.A=X;
guidata(hObject, handles);

% --- 打开图像.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton4.
function pushbutton4_ButtonDownFcn(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)


% --- 对比度2
function slider5_Callback(hObject, eventdata, handles)
% hObject    handle to slider5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=handles.A;
% -1:0.2:1 -->   0.1:10
v=get(handles.slider5,'value')*50 50
axes(handles.axes4); cla reset;
img = ContrastAdjust(I,v);
imshow(img),title('对比度调节');

% 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 slider5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider5 (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


% --- 饱和度2.
function slider6_Callback(hObject, eventdata, handles)
% hObject    handle to slider6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
I=handles.A;
% -1:0.2:1 -->   0.1:10
v=get(handles.slider6,'value');
if v<0
    m=1 v
end
if v>=0
    m=v*10
end
    
axes(handles.axes4); cla reset;
I=rgb2hsi(I);
% figure;                                                                                                                                                                                                              
% imshow(I);title('HSI域');
H1=I(:,:,1);
S1=I(:,:,2)*m;
X1=I(:,:,3); % 亮度调节
% 色度 饱和度 强度
I=cat(3,H1,S1,X1);
f1=hsi2rgb(I);
imshow(f1),title('HSI饱和度调节');
% 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 slider6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider6 (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


% --- 背景去噪
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)
I=handles.A;
a=5;
% 平滑滤波-高斯滤波
W = fspecial('gaussian',[a,a],1);
I = imfilter(I, W, 'replicate');
axes(handles.axes4); cla reset;
imshow(I);title('背景去噪');


% --- 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)
close;

实例下载地址

HSI图像处理及GUI设计

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警