www.gusucode.com > 《matlab图像处理与界面编程宝典》秦襄培 编著,每章的MATLAB源代码程序 > 第24章/代码24-3.txt
I = imread('rice.png'); % 读入图像 BW = im2bw(I, graythresh(I)); % 图像黑白转换 [B,L] = bwboundaries(BW,'noholes'); % 描绘边界 imshow(label2rgb(L, @jet, [.5 .5 .5])) % 显示标识图像 hold on % 继续绘图 for k = 1:length(B) boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2) % 描绘边界,为白色 end