matlab 提取目标 并进项任意轮廓最小外接矩形代码及其实现
2017-12-25 22:30
579 查看
matlab 任意轮廓外接矩形代码及其实现;
clc;clear;close all;I=imread('00121.bmp');
I=rgb2gray(I);
subplot(3,3,1);imshow(I);
% M=im2double(I);%将unit8转成double型
subplot(3,3,2),imhist(I);
M1=im2bw(I,25/255);%二值图level取值0~1.
subplot(3,3,3);imshow(M1);
BW1=1-M1;%取反操作
subplot(3,3,4);imshow(BW1);
BW2=bwareaopen(BW1,100000,4);%形态学操作,删除二值图像BW中面积小于10000的对象,4邻域
subplot(3,3,5);imshow(BW2);
BW3=1-BW2;
subplot(3,3,6);imshow(BW3);
BW=bwareaopen(BW3,90000);%形态学操作,删除二值图像BW中面积小于10000的对象,8邻域
subplot(3,3,7);imshow(BW);xlabel('除去背景后的完整二值图');
se=strel('disk',4);
% se1=strel('disk',4);
J=imerode(BW,se);
% J1=imerode(BW,se1);
J=BW-J;
subplot(3,3,8);imshow(J);xlabel('4直径');
% subplot(3,3,8);imshow(J1);xlabel('4直径');
J=edge(BW,'canny',0.3,2);
subplot(3,3,9);imshow(J);
整理好的下面。 clc;clear;close all;
I=imread('00073.bmp');
I=rgb2gray(I);
subplot(3,3,1);imshow(I);
%%
% M=im2double(I);%将unit8转成double型
subplot(3,3,2),imhist(I);
M1=im2bw(I,25/255);%二值图level取值0~1.
subplot(3,3,3);imshow(M1);
BW1=1-M1;%取反操作
subplot(3,3,4);imshow(BW1);
BW2=bwareaopen(BW1,100000,4);%形态学操作,删除二值图像BW中面积小于10000的对象,4邻域
subplot(3,3,5);imshow(BW2);
BW3=1-BW2;
subplot(3,3,6);imshow(BW3);
BW=bwareaopen(BW3,90000);%形态学操作,删除二值图像BW中面积小于10000的对象,8邻域
subplot(3,3,7);imshow(BW);xlabel('除去背景后的完整二值图');
%%
se=strel('disk',4);
% se1=strel('disk',4);
J=imerode(BW,se);
% J1=imerode(BW,se1);
J=BW-J;
J=bwmorph(J,'clean',10);%清除杂点,孤立点
J=bwmorph(J,'spur',Inf);%去除小分支,去毛刺
subplot(3,3,8);imshow(J);xlabel('4直径');
%%
[x,y]=find(J==1);%%返回的是行列像素不为0的点的纵坐标,横坐标
xmi=min(x(:));
xma=max(x(:));
ymi=min(y(:));
yma=max(y(:));
dx=xma-xmi; %%矩形宽
dy=yma-ymi; %%矩形长
rectangle('Position',[ ymi xmi dy dx],'EdgeColor','g', 'LineWidth',1);
s=dy*dx;
% [BW,thresh] = edge(BW,'canny');
Jj=edge(BW,'canny',[0.0063,0.0156],1.4);%灵敏度,高斯滤波标准差1.4
j=bwmorph(Jj,'clean',10);
subplot(3,3,9);imshow(j); %%
L=bwlabel(j,8);%标记连通区域,选择8邻域则可以标记成功,
stats=regionprops(L,'BoundingBox');
temp = stats.BoundingBox;
rectangle('position',temp,'edgecolor','r');
clc;clear;close all;
I=imread('00121.bmp');
I=rgb2gray(I);
subplot(3,3,1);imshow(I);
% M=im2double(I);%将unit8转成double型
subplot(3,3,2),imhist(I);
M1=im2bw(I,25/255);%二值图level取值0~1.
subplot(3,3,3);imshow(M1);
BW1=1-M1;%取反操作
subplot(3,3,4);imshow(BW1);
BW2=bwareaopen(BW1,100000,4);%形态学操作,删除二值图像BW中面积小于10000的对象,4邻域
subplot(3,3,5);imshow(BW2);
BW3=1-BW2;
subplot(3,3,6);imshow(BW3);
BW=bwareaopen(BW3,90000);%形态学操作,删除二值图像BW中面积小于10000的对象,8邻域
subplot(3,3,7);imshow(BW);xlabel('除去背景后的完整二值图');
se=strel('disk',4);
% se1=strel('disk',4);
J=imerode(BW,se);
% J1=imerode(BW,se1);
J=BW-J;
J=bwmorph(J,'clean',10);
subplot(3,3,8);imshow(J);xlabel('4直径');
[x,y]=find(J==1);%%返回的是行列像素不为0的点的纵坐标,横坐标
xmi=min(x(:));
xma=max(x(:));
ymi=min(y(:));
yma=max(y(:));
dx=xma-xmi; %%矩形宽
dy=yma-ymi; %%矩形长
rectangle('Position',[ ymi xmi dy dx],'EdgeColor','g', 'LineWidth',1);
s=dy*dx;
[BW,thresh] = edge(BW,'canny');
Jj=edge(BW,'canny',[0.0063,0.0156],1.4);%灵敏度,高斯滤波标准差1.4
j=bwmorph(Jj,'clean',10);
j=bwmorph(Jj,'spur',10);%去除小分支,去毛刺
subplot(3,3,9);imshow(j); %%
L=bwlabel(j,8);
stats=regionprops(L,'BoundingBox');
temp = stats.BoundingBox;
rectangle('position',temp,'edgecolor','r'); 阅读更多
相关文章推荐
- Radon变换及其Matlab代码实现
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- Matlab实现meanshift算法,目标跟踪代码实现
- 【OpenCV3图像处理】提取轮廓的凸包、外包矩形、最小外包矩形、最小外包圆
- 结合轮廓显示,实现完整的框选目标(附Demo代码)
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- 压缩感知中的常见测量矩阵及其MATLAB实现代码
- matlab 提取一个图形对象的最小外接矩形 并计算出面积
- MFCC特征提取的MatLab的代码实现
- [教程] 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- unity3d结合轮廓显示,实现完整的框选目标(附Demo代码)
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- unity3d结合轮廓显示,实现完整的框选目标(附Demo代码)
- [脚本]结合轮廓显示,实现完整的框选目标(附Demo代码)
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- 多种图像的颜色/纹理描述子及其matlab代码实现 相似性量测方法
- Hessian矩阵提取特征点原理及其Matlab实现
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- [转]结合轮廓显示,实现完整的框选目标(附Demo代码)