Detection Green Balls
来源:互联网 发布:阿里云cdn测评 编辑:程序博客网 时间:2024/06/15 01:32
Detection Green Balls
In the following pictures, a green ball is photographed. Detection the green ball is our mission.
.........................................
Collect Data
I use matlab function roipoly to collect HSV data.
There are 19 images as training samples.
The data obtained is (8022,3 ) double array.
Its columns are H,S,V values respectively.
The code to collect HSV data.
close allimagepath = './train';Samples = [];for k=1:19 % Load image I = imread(sprintf('%s/%03d.png',imagepath,k)); I = rgb2hsv(I); H = I(:,:,1); S = I(:,:,2); V = I(:,:,3); % Collect samples disp(''); disp('INTRUCTION: Click along the boundary of the ball. Double-click when you get back to the initial point.') disp('INTRUCTION: You can maximize the window size of the figure for precise clicks.') figure(1), mask = roipoly(I); figure(2), imshow(mask); title('Mask'); sample_ind = find(mask > 0); h = H(sample_ind); s = S(sample_ind); v = V(sample_ind); Samples = [Samples; [h s v]]; % append Samples disp('INTRUCTION: Press any key to continue. (Ctrl+c to exit)') pauseend
visualization code:
figure, scatter3(Samples(:,1),Samples(:,2),Samples(:,3),'.');title('Pixel Color Distribubtion');xlabel('Red');ylabel('Green');zlabel('Blue');
Choose Model.
In this session, I choose Multivariate Gaussian Model.
where are matrices.
so, right now we need to use maximum likelihood estimation to learn the parameters .
Parameters Learning
Likelihood function .
because ,so ,and because ,
such that, , then .
Results
In this example, I chose 0.95 as the threshold. Any pixels whose probability are greater than 0.95 are marked.
At last, the centers of all marked pixels are found by matlab function bwconncomp.
The detection function is displayed as the following:
function [segI, loc] = detectBall(I)% hsv datamu = [0.1565,0.6163,0.5992];sig = [0.0003,-0.0002,-0.0002;-0.0002,0.0191,0.0059;-0.0002,0.0059,0.0024];thre = 0.95;I = im2double(I);I = rgb2hsv(I);mage = reshape(I, 120*160,3);GMM = mvnpdf(mage, mu,sig);GMM = reshape(GMM, 120,160);mage = GMM > thre;bw_biggest = false(size(mage));% all zerosCC = bwconncomp(mage);numPixels = cellfun(@numel,CC.PixelIdxList);[biggest,idx] = max(numPixels);bw_biggest(CC.PixelIdxList{idx}) = true;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Compute the location of the ball center%S = regionprops(CC,'Centroid');loc = S(idx).Centroid; % find centersegI = bw_biggest;end
- Detection Green Balls
- Green~~~
- Are Green Concerts Green?
- detection
- Green Sleeves
- Roedy Green
- Green Sleeves
- Green Scrollbar
- Green Day
- Going green
- Green Mutexes
- green uml
- Green threads
- Green vpn
- Green DAO
- Green学习
- Labeling Balls
- Dragon Balls
- 2.3 set
- Soldier and Number Game
- 洛谷 P1303 A*B Problem
- 嵌入式Linux学习:u-boot源码分析(3)--AM335X系列的2014.10版
- 从0到1学习node之简易的网络爬虫
- Detection Green Balls
- 洛谷 P1604 B进制星球
- C语言冒泡排序的实现
- unit 11-12作业
- 支付宝签名验证机制
- 谷哥的小弟学前端(08)——CSS基础知识(6)
- VC++创建快捷方式
- python数据分析之csv/txt数据的导入和保存
- 说了这么久大数据 究竟大数据与传统数据有啥不一样