clc;
clear all;
I=imread('test.jpg');
figure;
imshow(I);
title('原始图像');
bw=im2bw(I,graythresh(I)); %图像二值化
figure;
imshow(bw);
title('二值图像');
[b,l]=bwboundaries(bw,'noholes'); %搜索物体的外边界
figure;
imshow(label2rgb(l,@jet,[.5 .5 .5])); %以不同的颜色标记不同的区域,0像素点用0.50.050.5标记
hold on;
for k=1:length(b)
boundary=b{k}; %取出每一个线条的坐标画在在图像上
plot(boundary(:,2),boundary(:,1),'w','LineWidth',3);
clear all;
I=imread('test.jpg');
figure;
imshow(I);
title('原始图像');
bw=im2bw(I,graythresh(I)); %图像二值化
figure;
imshow(bw);
title('二值图像');
[b,l]=bwboundaries(bw,'noholes'); %搜索物体的外边界
figure;
imshow(label2rgb(l,@jet,[.5 .5 .5])); %以不同的颜色标记不同的区域,0像素点用0.50.050.5标记
hold on;
for k=1:length(b)
boundary=b{k}; %取出每一个线条的坐标画在在图像上
plot(boundary(:,2),boundary(:,1),'w','LineWidth',3);
end