首页 > 化工知识 > 【图像识别】基于颜色直方图实现危险品识别matlab代码

【图像识别】基于颜色直方图实现危险品识别matlab代码

时间:2021-11-25 来源: 浏览:

【图像识别】基于颜色直方图实现危险品识别matlab代码

原创 天天Matlab 天天Matlab
天天Matlab

TT_Matlab

每天分享一点Matlab资料,一起成长进步。需要定制程序添加qq1575304183

收录于话题 #图像处理matlab源码 254个 内容

1 简介

直方图均衡化 Histogram Equalization HE )技术 可以在图像增强 [2] 、光照补偿 [3] 、图像去雾 [4-5] 多个领域取 得很好的效果,可见其应用范围广。

2 部分代码

function varargout = main ( varargin ) % MAIN MATLAB code for main.fig %     MAIN, by itself, creates a new MAIN or raises the existing %     singleton*. % %     H = MAIN returns the handle to a new MAIN or the handle to %     the existing singleton*. % %     MAIN(’CALLBACK’,hObject,eventData,handles,...) calls the local %     function named CALLBACK in MAIN.M with the given input arguments. % %     MAIN(’Property’,’Value’,...) creates a new MAIN or raises the %     existing singleton*. Starting from the left, property value pairs are %     applied to the GUI before main_OpeningFcn gets called. An %     unrecognized property name or invalid value makes property application %     stop. All inputs are passed to main_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 main % Last Modified by GUIDE v2.5 19-Apr-2016 17:05:45 % Begin initialization code - DO NOT EDIT gui_Singleton = 1 ; gui_State = struct ( ’gui_Name’ ,       mfilename , ...                   ’gui_Singleton’ ,   gui_Singleton , ...                   ’gui_OpeningFcn’ , @ gui_OpeningFcn , ...                   ’gui_OutputFcn’ ,   @ main_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 % --- Outputs from this function are returned to the command line. function varargout = main_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 ; %%GUI界面初始化 function gui_OpeningFcn ( hObject , eventdata , handles , varargin ) axes ( handles . axes1 ) imshow ( ’GUI问号.jpg’ ) ; axes ( handles . axes2 ) imshow ( ’GUI问号.jpg’ ) ; axes ( handles . axes3 ) imshow ( ’GUI问号.jpg’ ) ; axes ( handles . axes4 ) imshow ( ’GUI问号.jpg’ ) ; handles . output = hObject ; set ( handles . slider1 , ’Value’ , 0.8 ); set ( handles . edit1 , ’String’ , 0.8 ) ; guidata ( hObject , handles ); %%打开测试图像 % --- Executes on button press in open_test_img. function open_test_img_Callback ( hObject , eventdata , handles ) % hObject   handle to open_test_img (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles   structure with handles and user data (see GUIDATA) global file %定义全局变量 [ filename , pathname ]= uigetfile ({ ’*.jpg’ ; ’*.bmp’ ; ’*.gif’ ; ’*.png’ ; ’*.tif’ ; ’*.tga’ }, ’选择测试图像’ ); %跳出对话框 file = strcat ( pathname , filename ); %生成完成的图像路径和图像名 I = imread ( file ); %读取图像 axes ( handles . axes1 ); %在第一个坐标系中显示打开的图片 imshow ( I ); %%进行训练 % --- Executes on button press in start_test. function start_test_Callback ( hObject , eventdata , handles ) % hObject   handle to start_test (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles   structure with handles and user data (see GUIDATA) global   filename   wav_num mydir wav_path_list %全局变量 h = waitbar ( 0 , ’正在训练,请稍等...’ ); for j = 1 : wav_num     str = strcat ( fullfile ( mydir , wav_path_list ( j ) . name ));     I = imread ( str );   [ count1 , I ] = GetRgbHist ( str );     Count { j }= count1 ;     II { j }= I ;     waitbar ( j / wav_num ) ; end save ( ’Parametre.mat’ , ’Count’ , ’II’ ); close ( h ); %%退出按钮 % --- Executes on button press in close. function close_Callback ( hObject , eventdata , handles ) % hObject   handle to close (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles   structure with handles and user data (see GUIDATA) close ; % --- Executes on button press in open_xunlian. function open_xunlian_Callback ( hObject , eventdata , handles ) % hObject   handle to open_xunlian (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles   structure with handles and user data (see GUIDATA) global   filename   wav_num mydir wav_path_list %全局变量 mydir = uigetdir ( ’c:’ , ’请选择训练样本所在的目录’ ); %跳出对话框 wav_path_list = dir ( fullfile ( mydir , ’*.jpg’ )); wav_num = length ( wav_path_list ); filename ={ wav_path_list . name }; str = sprintf ( ’该目录包含%d个图像文件’ , wav_num ); msgbox ( str ); %%开始检测 % --- Executes on button press in start_jiance. function start_jiance_Callback ( hObject , eventdata , handles ) % hObject   handle to start_jiance (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles   structure with handles and user data (see GUIDATA) load ’Parametre.mat’ ; [ a , b ]= size ( II ); global file   [ count2 , I2 ] = GetRgbHist ( file ); %bbbbb=count2 for i = 1 : b value ( i ) = imsimilar ( Count { i }, count2 , 2 ); end maxvalue = max ( value ); [ row col ]= find ( maxvalue == value ); axes ( handles . axes2 ); imshow ( II { col }); axes ( handles . axes3 ); plot ( Count { col }); hold on ; plot ( count2 , ’r’ ); legend ( ’测试图’ , ’近似图’ , 2 ); str = sprintf ( ’图像直方图 相似测试 相似度为:%s %%’ , num2str ( value ( col ))); title ( str ); A =( get ( handles . slider1 , ’Value’ )) * 100 if maxvalue > = A     axes ( handles . axes4 );     imshow ( ’危险品.jpg’ );   [ y , fs ]= audioread ( ’警报.mp3’ );     sound ( y , fs ); else     axes ( handles . axes4 );     imshow ( ’正常.png’ ); end guidata ( hObject , handles ) ; % --- 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 temp_Invisible_w = get ( hObject , ’Value’ ) ; set ( handles . edit1 , ’String’ , num2str ( temp_Invisible_w ) ) ; handles . Invisible_w = temp_Invisible_w ; guidata ( hObject , handles ) ; % --- 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 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 value0 = str2double ( get ( hObject , ’String’ ) ) ; if isnan ( value0 )     msgbox ( ’要输入数字才行哦!’ );     set ( hObject , ’String’ , ’0’ );     set ( handles . slider1 , ’Value’ , 0 ); elseif value0 < 0 | value0 > 1     msgbox ( ’只能数入0-1才行哦!’ );     set ( hObject , ’String’ , ’0’ );     set ( handles . slider1 , ’Value’ , value0 ); else     set ( handles . slider1 , ’Value’ , value0 );     handles . edit1 = value0 ;     guidata ( hObject , handles ) ; end % --- 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

3 仿真结果

4 参考文献

[1]张懿, 刘旭, and 李海峰. "自适应图像直方图均衡算法." 浙江大学学报(工学版) 41.4(2007):630-633.

天天Matlab

赞赏二维码 微信扫一扫赞赏作者 赞赏

已喜欢, 对作者说句悄悄话
最多40字,当前共

  人赞赏

1 / 3

长按二维码向我转账

赞赏二维码

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

版权:如无特殊注明,文章转载自网络,侵权请联系cnmhg168#163.com删除!文件均为网友上传,仅供研究和学习使用,务必24小时内删除。
相关推荐