识别圆形物体
来源:互联网 发布:nba最新数据统计 编辑:程序博客网 时间:2024/05/01 05:21
Step 1: Read Image
Read in pills_etc.png
.
RGB = imread('pillsetc.png');imshow(RGB);
Step 2: Threshold the Image
Convert the image to black and white in order to prepare for boundary tracing usingbwboundaries
.
I = rgb2gray(RGB);bw = imbinarize(I);imshow(bw)
Step 3: Remove the Noise
Using morphology functions, remove pixels which do not belong to the objects of interest.
% remove all object containing fewer than 30 pixelsbw = bwareaopen(bw,30);% fill a gap in the pen's capse = strel('disk',2);bw = imclose(bw,se);% fill any holes, so that regionprops can be used to estimate% the area enclosed by each of the boundariesbw = imfill(bw,'holes');imshow(bw)
Step 4: Find the Boundaries
Concentrate only on the exterior boundaries. Option 'noholes' will accelerate the processing by preventingbwboundaries
from searching for inner contours.
[B,L] = bwboundaries(bw,'noholes');% Display the label matrix and draw each boundaryimshow(label2rgb(L, @jet, [.5 .5 .5]))hold onfor k = 1:length(B) boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)end
Step 5: Determine which Objects are Round
Estimate each object's area and perimeter. Use these results to form a simple metric indicating the roundness of an object:
metric = 4*pi*area/perimeter^2.
This metric is equal to one only for a circle and it is less than one for any other shape. The discrimination process can be controlled by setting an appropriate threshold. In this example use a threshold of 0.94 so that only the pills will be classified as round.
Use regionprops
to obtain estimates of the area for all of the objects. Notice that the label matrix returned bybwboundaries
can be reused by regionprops
.
stats = regionprops(L,'Area','Centroid');threshold = 0.94;% loop over the boundariesfor k = 1:length(B) % obtain (X,Y) boundary coordinates corresponding to label 'k' boundary = B{k}; % compute a simple estimate of the object's perimeter delta_sq = diff(boundary).^2; perimeter = sum(sqrt(sum(delta_sq,2))); % obtain the area calculation corresponding to label 'k' area = stats(k).Area; % compute the roundness metric metric = 4*pi*area/perimeter^2; % display the results metric_string = sprintf('%2.2f',metric); % mark objects above the threshold with a black circle if metric > threshold centroid = stats(k).Centroid; plot(centroid(1),centroid(2),'ko'); end text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',... 'FontSize',14,'FontWeight','bold'); endtitle(['Metrics closer to 1 indicate that ',... 'the object is approximately round']);
- 识别圆形物体
- 物体识别
- 物体识别
- 物体识别
- 空间圆形物体的检测
- Surface物体识别
- 物体的形状识别
- 家庭物体识别调研
- Features2D + Homography物体识别
- unity AR3D物体识别
- 实时物体识别框架
- opencv识别圆形
- 刚性物体 识别技术综述
- 稀疏表征与物体识别
- 物体识别系统的流程
- 二维物体形状识别方法
- RGBD物体识别(1)--开篇
- opencv--颜色物体识别跟踪
- Android 关于BottomDialogSheet 与Layout擦出爱的火花?
- Android好用的轮播图控件
- 面试中的坑,你能爬出来几个?
- JavaScript与JSON
- 最近参与的项目小结
- 识别圆形物体
- js数字位数太大导致参数精度丢失问题
- LeetCode 551. Student Attendance Record I
- Shiro整合Spring maven
- matlab 数据读取
- Leetcode 282. Expression Add Operators
- ZOJ3768-Continuous Login
- 样本不平衡--SMOTE算法-学习笔记
- iOS获取通讯录