⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pattern242.m

📁 孙即祥
💻 M
字号:
%模式识别 2.4.2 P26%相似性阈值聚类仿真%追加方法%a=zeros(1,5) a=a+delta%a=[] a=[a delta]clear allclose allim1=imread('pattern.bmp');im=rgb2gray(im1);[row col]=size(im);imshow(im);hold on;[targetx,targety]=getpts;points=[targetx,targety];[NumOfPoints,colzcn]=size(points);plot(targetx,targety,'b*');%选第一点为聚类中心centerx=points(1,1);centery=points(1,2);%text(centerx, centery+5, sprintf('1'), 'Color', 'r', 'Fontsize', 15);plot(centerx,centery,'rs');%设置距离阈值T=80;Mdistance=[];%for i=1:NumOfPoints    distancex=points(i,1)-centerx;    distancey=points(i,2)-centery;    distance=sqrt(distancex.^2+distancey.^2);    Mdistance=[Mdistance distance];end[x,y]=find(Mdistance<T);%找到在距离矩阵中小于距离阈值的坐标,即Mdistance坐标。coordinate=[x',y'];%把M阵的坐标排成合适方式。Inner=points(y',:);%找到Mdistance坐标与points阵的传递关系%在本例中发现M阵中的y'等于点击坐标点的顺序值,亦等于points阵的行号。%也就是M阵中的最佳点的序号等效于Points阵的最佳位置号,至于points%最佳位置号中又代表的是图片的坐标那就是另一个问题了,不要混淆。%画框%切忌这是plot而不是图片上的image([],())=0之类,一条一条的画。gatherx=Inner(:,1);gathery=Inner(:,2);mingatherx=min(gatherx);maxgatherx=max(gatherx);mingathery=min(gathery);maxgathery=max(gathery);left=mingatherx;top=mingathery;right=maxgatherx;bottom=maxgathery;hold on;plot(left,(top:bottom),'-k.');plot(right,(top:bottom),'-k.');plot((left:right),top,'-k.');plot((left:right),bottom,'-k.');%画圆NumOfGatherPoint=length(y);MdistancePointToCenter=[];for j=1:NumOfGatherPoint    %变量名最长不超过63    DistancePointToCenter=sqrt((centerx-Inner(j,1)).^2+...        (centery-Inner(j,2)).^2);    MdistancePointToCenter=[MdistancePointToCenter ...        DistancePointToCenter];end[GatherPointx,GatherPointy]=max(MdistancePointToCenter);% MatrixDistance->MatrixInner mapping!InnerMaxDistancePointValue=Inner(GatherPointy,:);% quote Inner Value For DrawingMaxPointx=InnerMaxDistancePointValue(1,1);MaxPointy=InnerMaxDistancePointValue(1,2);radius=sqrt((MaxPointx-centerx).^2+(MaxPointy-centery).^2);xx=(centerx-radius):0.005:(centerx+radius);%%%%步长决定缺口yyup=centery-sqrt(radius.^2-(xx-centerx).^2);yydown=centery+sqrt(radius.^2-(xx-centerx).^2);plot(xx,yyup,'g.','LineWidth',2);plot(xx,yydown,'g.','LineWidth',2);hold off;%问题注意%寻找方法解决%对应方法解决%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -