【图像识别】基于颜色直方图实现危险品识别matlab代码
【图像识别】基于颜色直方图实现危险品识别matlab代码
TT_Matlab
每天分享一点Matlab资料,一起成长进步。需要定制程序添加qq1575304183
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.
微信扫一扫赞赏作者
赞赏
发送给作者
人赞赏
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
-
Origin(Pro):学习版的窗口限制【数据绘图】 2020-08-07
-
如何卸载Aspen Plus并再重新安装,这篇文章告诉你! 2020-05-29
-
AutoCAD 保存时出现错误:“此图形中的一个或多个对象无法保存为指定格式”怎么办? 2020-08-03
-
OriginPro:学习版申请及过期激活方法【数据绘图】 2020-08-06
-
CAD视口的边框线看不到也选不中是怎么回事,怎么解决? 2020-06-04
-
教程 | Origin从DSC计算焓和比热容 2020-08-31
-
如何评价拟合效果-Origin(Pro)数据拟合系列教程【数据绘图】 2020-08-06
-
Aspen Plus安装过程中RMS License证书安装失败的解决方法,亲测有效! 2021-10-15
-
CAD外部参照无法绑定怎么办? 2020-06-03
-
CAD中如何将布局连带视口中的内容复制到另一张图中? 2020-07-03