下面是一个使用bwboundaries和axes函数的Matlab代码示例:
% 创建一个二值图像
image = zeros(100, 100);
image(30:70, 30:70) = 1;
% 使用bwboundaries函数获取二值图像的边界
boundaries = bwboundaries(image);
% 绘制图像和边界
figure;
imagesc(image);
colormap gray;
hold on;
for k = 1:length(boundaries)
boundary = boundaries{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2);
end
% 设置坐标轴
axis image;
axis off;
这段代码首先创建一个100x100的全黑图像,然后在图像的中心区域绘制一个白色方块。接下来,使用bwboundaries函数获取二值图像的边界。最后,使用axes函数绘制图像和边界,并设置坐标轴为图像大小,并关闭坐标轴的显示。
运行代码后,将会显示原始图像和检测到的边界。