Matlab中regionprops的使用示例
2016-05-14 16:46
549 查看
版权声明:本文为shaoxiaohu原创文章,欢迎转载,请注明出处,谢谢。
有这样一幅图,
我们想获取其中的连通区域,可以使用以下代码:
[plain] view
plain copy
src_img_name = 'blue_sky_white_clound_002594.jpg';
img = imread(src_img_name);
% get binary image
gray_img = rgb2gray(img);
T = graythresh(gray_img);
bw_img = im2bw(gray_img, T);
% find the largest connected region
img_reg = regionprops(bw_img, 'area', 'boundingbox');
areas = [img_reg.Area];
rects = cat(1, img_reg.BoundingBox);
显示所有连通区域,
[plain] view
plain copy
% show all the largest connected region
figure(1),
imshow(bw_img);
for i = 1:size(rects, 1)
rectangle('position', rects(i, :), 'EdgeColor', 'r');
end
显示最大连通区域,
[plain] view
plain copy
[~, max_id] = max(areas);
max_rect = rects(max_id, :);
% show the largest connected region
figure(2),
imshow(bw_img);
rectangle('position', max_rect, 'EdgeColor', 'r');
有这样一幅图,
我们想获取其中的连通区域,可以使用以下代码:
[plain] view
plain copy
src_img_name = 'blue_sky_white_clound_002594.jpg';
img = imread(src_img_name);
% get binary image
gray_img = rgb2gray(img);
T = graythresh(gray_img);
bw_img = im2bw(gray_img, T);
% find the largest connected region
img_reg = regionprops(bw_img, 'area', 'boundingbox');
areas = [img_reg.Area];
rects = cat(1, img_reg.BoundingBox);
显示所有连通区域,
[plain] view
plain copy
% show all the largest connected region
figure(1),
imshow(bw_img);
for i = 1:size(rects, 1)
rectangle('position', rects(i, :), 'EdgeColor', 'r');
end
显示最大连通区域,
[plain] view
plain copy
[~, max_id] = max(areas);
max_rect = rects(max_id, :);
% show the largest connected region
figure(2),
imshow(bw_img);
rectangle('position', max_rect, 'EdgeColor', 'r');
相关文章推荐
- MATLAB实现图像镜像变换的源代码!
- MATLAB实现图像平移的源代码!
- Matlab Tricks(七)—— 矩阵列/列的归一化/单位化(normalize)
- MATLAB的imtransform()函数作图像线性平移时如果要体现效果要加上目标Size限制!
- Matlab Tricks(六)—— 矩阵乘法的实现
- matlab win7 64bit 找不到vs2013编译器解决办法
- matlab文件IO(读取写入)2 低级例程
- MATLAB和VS混合编程
- matlab/简单的滤波程序
- MATLAB时间序列预测Prediction of time series with NAR neural network
- matlab文件IO(读取写入)1 高级例程
- Error using xlsread (matlab 读取文件报错)
- MATLAB逻辑函数
- Matlab代码的耗时分析、优化、加速
- Matlab Tricks(五)—— shuffle 一个矩阵
- matlab中size和length求解矩阵大小的区别
- Compute Mean Value of Train and Test Dataset of Caltech-256 dataset in matlab code
- NSGA-ⅡMATLAB代码(转载)
- matlab 二进制文件的读取fead,节约内存
- matlab调用opencv的函数