function varargout = uxxntitled(varargin)
% UXXNTITLED MATLAB code for uxxntitled.fig
% UXXNTITLED, by itself, creates a new UXXNTITLED or raises the existing
% singleton*.
%
% H = UXXNTITLED returns the handle to a new UXXNTITLED or the handle to
% the existing singleton*.
%
% UXXNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UXXNTITLED.M with the given input arguments.
%
% UXXNTITLED('Property','Value',...) creates a new UXXNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before uxxntitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to uxxntitled_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 uxxntitled
% Last Modified by GUIDE v2.5 26-Apr-2022 08:58:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @uxxntitled_OpeningFcn, ...
'gui_OutputFcn', @uxxntitled_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
% End initialization code - DO NOT EDIT
% --- Executes just before uxxntitled is made visible.
function uxxntitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to uxxntitled (see VARARGIN)
% Choose default command line output for uxxntitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes uxxntitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = uxxntitled_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = imread('1.jpg');
axes(handles.axes4)
imshow(i)
title('原图')
i1=rgb2gray(i); %转灰度图像
i2=imbinarize(i1); %二值化搜索
axes(handles.axes5)
imshow(i2)
title('二值化搜索')
i3 = bwmorph(i2,'close'); %闭运算
axes(handles.axes1)
imshow(i3)
title('闭合运算')
i3 = ~i3;
i4 = bwareaopen(i3,8000);
i4 = imcrop(i4, [2,2,size(i4,2)-2, size(i4,1)-2]);
%去除小的干扰,再去除边界的一圈1
%figure, imshow(i4)
% clc;
% clear;
% close all;
% I=imread ( 'E:\树叶图片\untitled1.jpg ');
% I=imbinarize(I) ;
I = i4;
[m,n]=size(I) ;%计算图像的大小
axes(handles.axes2)
imshow(I);
BWimg=I;
hold on
title('二值化')
se=strel('disk',5);
BWimg = imclose(BWimg,se);%%进行关闭运算
BWimg = imopen(BWimg,se);%进行开运算
[mark_image,num] = bwlabel(BWimg,4);
status=regionprops(mark_image,'BoundingBox');%%d得到连通域 并且道到每个联通的区域
centroid = regionprops(mark_image,'Centroid');%得到联通的中心
for i=1:num
rectangle('position',status(i).BoundingBox,'edgecolor','r');%标记出来中心位置 画图框
end
title(['面积=',num2str(status(i).BoundingBox(3)*status(i).BoundingBox(4))])
R=0;%二值图像的背景像素
I0=zeros(m+2,n+2)+R;%原图像+边框,避免边界查找出错
I0(2: (m+1 ),2:(n+1))=I;
x0=0 ;
y0=0 ;
fsp=0 ;%是否找到起始点
%%%%%%%%%寻找目标区域的一个边界点%
for i=1:m
for j=1:n
if (I0(i,j)~=R)
x0=i;%记录起始点的纵坐标i
y0=j;%记录起始点的横坐标j
%fsp=l;
fsp = 1;
break;
end
end
if fsp==1
break;
end
end
row=x0;
col=y0;
%按某一方向查找边界坐标并且记录%
A=[];%存储边界点坐标的矩阵
B=zeros(m,n);%边界跟踪的图像矩阵ended=0 ;
ended=0 ;
direction=4;%由起始点的左边开始查找
while (ended==0 )
found_next=0;
%b=[ row-l,col-1];%消除边框,与原图保持一致
b = [row-1,col-1];
A=[A; b];
%B(row-1,col-1)=255;
B(row-1,col-1)=255;
while(found_next==0)
switch mod (direction,8)
%case o
case 0
%if (IO(row ,col+1)~=R)
if (I0(row ,col+1)~=R)
row=row ;%记录当前坐标
col=col+1;
direction=5;%下一点由方向5开始查找
found_next=1;%找到边界点,准备跳出循环
end
case 1
if (I0 (row-1,col+1)~=R)
row=row-1;%记录当前坐标
col=col+1;
direction=6;%下一点由方向6开始查找
found_next=1;%找到边界点
end
case 2
if (I0 (row-1,col) ~=R)
row=row-1;
%记录当前坐标
col=col;
direction=7;%下一点由方向7开始查找
found_next=1;%找到边界点
end
case 3
if (I0( row-1,col-1)~=R)
row=row-1;%记录当前坐标
col=col-1;
direction=0;%下一点由方向0开始查找
found_next=1;%找到边界点
end
case 4
if(I0(row,col-1)~=R)
row=row;%记录当前坐标
col=col-1;
direction=1;%下一点由方向1开始查找
found_next=1;%找到边界点
end
case 5
if(I0(row+1,col-1)~=R)
row=row+1;%记录当前坐标
col=col-1;
direction=2;%下一点由方向2开始查找
found_next=1;%找到边界点
end
case 6
if(I0(row+1,col)~=R)
row=row+1;%记录当前坐标
col=col;
direction=3;%下一点由方向3开始查找
found_next=1;%找到边界点
end
case 7
if(I0(row+1,col+1)~=R)
row=row+1;%记录当前坐标
col=col+1;
direction=4;%下一点由方向4开始查找
found_next=1;
%找到边界点
end
end
if(found_next==0)
direction=direction+1;%未找到边界点,继续在下一方向查找
end
end
if(and((x0==row),(y0==col)))
ended=1;%是否与起始点相同
end
end
A1=[A;[x0-1,y0-1]];
axes(handles.axes3)
imshow (B);%输出跟踪结果
hold on
%%%求出8方向链码%%%%
C=[];
for i=1:length(A1)-1
if(A1(i+1,1)-A1(i,1)==0)&&(A1(i+1,2)-A1(i,2)==1)
code=0 ;
C=[C,code ];
end
if(A1(i+1,1)-A1(i,1)==-1)&&(A1(i+1,2)-A1(i,2)==1)
code=1;
C=[C,code];
end
if(A1(i+1,1)-A1(i,1)==-1)&& (A1(i+1,2)-A1(i,2)==0)
物体尺寸测量-matlab
版权申诉
5星 · 超过95%的资源 39 浏览量
2022-04-26
17:50:38
上传
评论 14
收藏 557KB RAR 举报
人工智能专属驿站
- 粉丝: 274
- 资源: 174
最新资源
- 基于matlab实现串口发送接收数据 可配置端口,波特率等 发送可选择ASCII方式或HEX方式
- matlab基于BP神经网络手写字母识别(单一).zip代码9
- 基于matlab实现编写的串口调试工具,数据接收部分采用中断方式,保证了实时的数据显示
- 基于matlab实现39节点电力系统合闸角调控过程中的机组和负荷的灵敏度计算.rar
- HBase数据库性能调优
- 原生微信小程序源码 - -首字母排序选择
- 基于QT+C++开发的保卫萝卜塔防游戏+源码(毕业设计&课程设计&项目开发)
- newapp.apk
- 项目申报管理系统论文Java项目
- 8数码、α-β搜索的博弈树算法编写一字棋游戏、Fisher线性分类器、感知器算法、SVM 分类器、卷积神经网络 CNN 框架
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页