【matlab】bwboundaries的用法示例

版权声明:转载时打个招呼。 https://blog.csdn.net/qq_15971883/article/details/82426169

覆盖图像上的区域边界

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

效果如下:

标记目标物体边缘(在matlab代码练习12中也提到标记目标物体边缘的方法)

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 = bwboundaries(BW, 'noholes'); 
imshow(I); 
hold on; 
for k = 1 : length(B) % 边界着色
    thisBoundary = B{k}; 
    plot(thisBoundary(:, 2), thisBoundary(:, 1), 'r', 'LineWidth', 2); 
end

猜你喜欢

转载自blog.csdn.net/qq_15971883/article/details/82426169
今日推荐