有这样的照片。
我想获取其中的联系区域,可以使用以下代码。
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 );
显示所有连通区域,
% showallthelargestconnectedregion
图形(1)、
imshow(bw_img );
forI=1:size(Rects,1 ) ) ) ) ) ) ) )。
rectangle('position ',rects(i ) I, ),' EdgeColor ',' r ' );
结束
显示最大连通区域,
[~,max_id]=max(areas );
max_rect=rects(max_id, );
% show the largest connected region
图形(2)、
imshow(bw_img );
rectangle('position ',max_rect,' EdgeColor ',' r ' );