覆盖图像上的区域边界
close all;
clear;
clc;
% Read grayscale image into the workspace
I = imread('rice.png');
% Convert grayscale image to binary image using local adaptive thresholding
BW = imbinarize(I);
% Calculate boundaries of regions in image and overlay the boundaries on the image
[B, L] = bwboundaries(BW, 'noholes');
imshow(label2rgb(L, @jet, [0.5, 0.5, 0.5])); % 伪彩显示
hold on;
for k = 1 : length(B) % 边界着色
boundary = B{k};
plot(boundary(:, 2), boundary(:, 1), 'k', 'LineWidth', 2);
end
效果如下:
标记目标物体边缘(在