【圖像識(shí)別】基于顏色直方圖實(shí)現(xiàn)危險(xiǎn)品識(shí)別matlab代碼
【圖像識(shí)別】基于顏色直方圖實(shí)現(xiàn)危險(xiǎn)品識(shí)別matlab代碼
TT_Matlab
每天分享一點(diǎn)Matlab資料,一起成長(zhǎng)進(jìn)步。需要定制程序添加qq1575304183
1 簡(jiǎn)介
直方圖均衡化 ( Histogram Equalization , HE )技術(shù) 可以在圖像增強(qiáng) [2] 、光照補(bǔ)償 [3] 、圖像去霧 [4-5] 多個(gè)領(lǐng)域取 得很好的效果,可見其應(yīng)用范圍廣。
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問號(hào).jpg’ ) ; axes ( handles . axes2 ) imshow ( ’GUI問號(hào).jpg’ ) ; axes ( handles . axes3 ) imshow ( ’GUI問號(hào).jpg’ ) ; axes ( handles . axes4 ) imshow ( ’GUI問號(hào).jpg’ ) ; handles . output = hObject ; set ( handles . slider1 , ’Value’ , 0.8 ); set ( handles . edit1 , ’String’ , 0.8 ) ; guidata ( hObject , handles ); %%打開測(cè)試圖像 % --- 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’ }, ’選擇測(cè)試圖像’ ); %跳出對(duì)話框 file = strcat ( pathname , filename ); %生成完成的圖像路徑和圖像名 I = imread ( file ); %讀取圖像 axes ( handles . axes1 ); %在第一個(gè)坐標(biāo)系中顯示打開的圖片 imshow ( I ); %%進(jìn)行訓(xùn)練 % --- 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 , ’正在訓(xùn)練,請(qǐng)稍等...’ ); 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:’ , ’請(qǐng)選擇訓(xùn)練樣本所在的目錄’ ); %跳出對(duì)話框 wav_path_list = dir ( fullfile ( mydir , ’*.jpg’ )); wav_num = length ( wav_path_list ); filename ={ wav_path_list . name }; str = sprintf ( ’該目錄包含%d個(gè)圖像文件’ , wav_num ); msgbox ( str ); %%開始檢測(cè) % --- 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 ( ’測(cè)試圖’ , ’近似圖’ , 2 ); str = sprintf ( ’圖像直方圖 相似測(cè)試 相似度為:%s %%’ , num2str ( value ( col ))); title ( str ); A =( get ( handles . slider1 , ’Value’ )) * 100 if maxvalue > = A axes ( handles . axes4 ); imshow ( ’危險(xiǎn)品.jpg’ ); [ y , fs ]= audioread ( ’警報(bào).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 ( ’要輸入數(shù)字才行哦!’ ); set ( hObject , ’String’ , ’0’ ); set ( handles . slider1 , ’Value’ , 0 ); elseif value0 < 0 | value0 > 1 msgbox ( ’只能數(shù)入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 仿真結(jié)果
4 參考文獻(xiàn)
[1]張懿, 劉旭, and 李海峰. "自適應(yīng)圖像直方圖均衡算法." 浙江大學(xué)學(xué)報(bào)(工學(xué)版) 41.4(2007):630-633.
微信掃一掃贊賞作者
贊賞
發(fā)送給作者
人贊賞
長(zhǎng)按二維碼向我轉(zhuǎn)賬
受蘋果公司新規(guī)定影響,微信 iOS 版的贊賞功能被關(guān)閉,可通過二維碼轉(zhuǎn)賬支持公眾號(hào)。
-
Origin(Pro):學(xué)習(xí)版的窗口限制【數(shù)據(jù)繪圖】 2020-08-07
-
如何卸載Aspen Plus并再重新安裝,這篇文章告訴你! 2020-05-29
-
CAD視口的邊框線看不到也選不中是怎么回事,怎么解決? 2020-06-04
-
教程 | Origin從DSC計(jì)算焓和比熱容 2020-08-31
-
CAD外部參照無法綁定怎么辦? 2020-06-03
-
CAD中如何將布局連帶視口中的內(nèi)容復(fù)制到另一張圖中? 2020-07-03
