matlab轮廓勾勒

2018-05-03  本文已影响0人  lfliu

clc;

clear;

target='D:\Users\LIULIFEN310\Desktop\testresult\bw\'

image='D:\Users\LIULIFEN310\Desktop\testresult\test\'

%image=''

dst='D:\Users\LIULIFEN310\Desktop\testresult\analysis\';

list=dir(fullfile(image));

fileNum=size(list,1)-2;

for k=3:fileNum

filename=list(k).name;

inputImage=[image,filename];

pos=strfind(filename,'.');

relateFile=[filename(1:pos),'png']

relateTarget=[target,relateFile];

imgTarget=imread(relateTarget);

imgTarget=double(imgTarget)*255;

%find couter

% bw=im2bw(imgTarget);

% bw2=bwperim(bw,8);

Image=imread(inputImage);

B = bwboundaries(imgTarget,8);%get boundry x,y

x=B{1,1}(:,1);%cell数据采用{}获取元素,array用[]获取元素

y=B{1,1}(:,2);%x为纵坐标,y为横坐标

l=length(x);

output=figure('Visible', 'off');%只写出figure,不显示

imshow(Image);

hold on;

for i=1:l

    plot(y(i),x(i),'b.');%

end

%Matlab的plot~各种颜色和线形 - CSDN博客

outputfile=[dst,filename(1:pos),'png'];

saveas(output,outputfile);

close(output);

end

matlab 计算连通域 - CSDN博客

上一篇 下一篇

猜你喜欢

热点阅读