标签:样本 image count 提取 定义 modified 一个 gets turn
1 直方图
再讲颜色直方图之前,先简单介绍一下直方图。 直方图作为一种简单有效的基于统计特性的特征描述子,在计算机视觉领域广泛使用。它的优点主要体现在两个方面:一是对于任意一个图像区域,直方图特征的提取简单方便;其二,直方图表征图像区域的统计特性,可以有效表示多模态的特征分布,并且本身具备一定的旋转不变性。因此,在计算机视觉领域,基于不同底层特征的各种新颖直方图描述子层出不穷,包括亮度直方图,颜色直方图,HOG,局部二值模式直方图[等。其中颜色直方图是目标跟踪领域最为广泛使用的描述子,然而传统的颜色直方图对光照变化敏感,同时目标区域内像素位置分布被完全忽略。
2 颜色直方图
也就是说明某一像素值范围的像素点的个数,X轴为像素值,Y为个数。
3 彩色直方图
彩色图像有三个通道,我们可以把它的三个通道分别取出来进行绘制。则可以看每个通道上像素的分布,得到原图中哪种颜色比较多。
3 直方图均衡化
直方图均衡化的作用是图像增强。
有两个问题比较难懂,一是为什么要选用累积分布函数,二是为什么使用累积分布函数处理后像素值会均匀分布。
第一个问题。均衡化过程中,必须要保证两个条件:①像素无论怎么映射,一定要保证原来的大小关系不变,较亮的区域,依旧是较亮的,较暗依旧暗,只是对比度增大,绝对不能明暗颠倒;②如果是八位图像,那么像素映射函数的值域应在0和255之间的,不能越界。综合以上两个条件,累积分布函数是个好的选择,因为累积分布函数是单调增函数(控制大小关系),并且值域是0到1(控制越界问题),所以直方图均衡化中使用的是累积分布函数。
第二个问题。累积分布函数具有一些好的性质,那么如何运用累积分布函数使得直方图均衡化?比较概率分布函数和累积分布函数,前者的二维图像是参差不齐的,后者是单调递增的。直方图均衡化过程中,映射方法是
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
版本:2014a
完整代码或代写加1564658423
【危险品识别】基于matlab颜色直方图危险品识别【含Matlab源码 470期】
标签:样本 image count 提取 定义 modified 一个 gets turn
原文地址:https://www.cnblogs.com/homeofmatlab/p/14944145.html